import java.io.InputStream;

class ITEC {

	private int next;

	private InputStream in;

	public class ParseError extends Exception {

		public String getMessage() {
			return "parse errror";
		}
	}

	public ITEC(InputStream in) throws Exception {
		this.in = in;
		next = in.read();
	}

	private void eat(int symbol) throws Exception {
		if (next != symbol)
			throw new ParseError();
		next = in.read();
	}

	private int E() throws Exception {
		if(next < '0' || next > '9')
			throw new ParseError();
		int val = next - '0';
		eat(next);
		return T(val);
	}

	private int T(int val) throws Exception {
		if(next == ':' || next == '\n')
			return val;
		if(next != '?')
			throw new ParseError();
		eat('?');
		int first = E();
		eat(':');
		int second = E();
		return val != 0 ? first : second;
	}

	public int parse() throws Exception {
		int val = E();
		if (next != '\n')
			throw new ParseError();
		return val;
	}

	public static void main(String[] args) {
		try {
			ITEC parser = new ITEC(System.in);
			int val = parser.parse();
			System.out.println(val);
		} catch (Exception e) {
			System.err.println(e.getMessage());
		}
	}
}
