Problem: The time was 3xxx, and the highly developed civilization was in a stagnation period. Historians decided to learn the wisdom of the past in an attempt to overcome this situation. What I paid attention to was the material left by the genius of the early days of computers. The calculation formula is written in this material and I would like to know the calculation result, but unfortunately some of the characters are fading and cannot be read. Since there is no help for it, I decided to find the largest possible number as a calculation result. The calculation formula is written in binary numbers, and there are three types of operations: addition, subtraction, and multiplication. Parentheses are also used, but the numbers inside the parentheses are not the only ones. To be exact, it is necessary to satisfy the grammar defined by the following BNF.


<expression> :: = <number> | <expression> <operation> <expression>
| (<expression> <operation> <expression>)
<number> :: = <digit> | <number> <digit>
<operation> :: = + |-| *
<digit> :: = 0 | 1


Due to the limited computing power of computers at that time, numbers are integers between 0 and 210 and do not go out of this range during calculations. However, the calculation is done in parentheses first, and the multiplication is done before addition / subtraction. In other cases, the calculation is performed in order from the left.

Constraints

* Formulas must be between 1 and 100 characters
* All characters except line breaks are either 01 +-* ().
*. Number is 5 or less

Input

The input consists of one line and is given one formula to decipher. The formula is 1 to 100 characters. Up to 5 characters cannot be read for one formula and are represented by ".". The characters contained in the given formula are either 01 +-* ().

Output

Find the one that maximizes the calculation result among the original formulas, and output the calculation result in decimal notation. Output -1 if you can't make what you think is the original formula no matter how you fill in the unreadable characters.

Examples

Input

000


Output

0


Input

0.0


Output

2


Input

...


Output

7


Input

(1.1)


Output

2


Input

0-1.


Output

-1

Solution (in CPP):

Solution:
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


char component_array[7] = {'0','1','+','-','*','(',')',};
int table[16807][7];
int num_of_blank,table_index;

int calc_E(char line[101],int left,int right);
int calc_T(char line[101],int left,int right);
int calc_F(char line[101],int left,int right);
int calc_NUM(char line[101],int left,int right);

bool rangeCheck(int number){
	if(number >= 0 && number <= 1023)return true;
	else{
		return false;
	}
}

void makeTable(int change_list[5],int index){

	if(index == num_of_blank){
		for(int i = 0; i < num_of_blank; i++){
			table[table_index][i] = change_list[i];
		}
		table_index++;
		return;
	}

	for(int i = 0; i < 7; i++){
		int next_change_list[5];
		for(int k = 0; k < index; k++)next_change_list[k] = change_list[k];
		next_change_list[index] = i;
		makeTable(next_change_list,index+1);
	}
}

bool is_OK(char work[101],int length){

	for(int i = 0; i < length; i++){
		if(work[i] == '(' && work[i+1] == ')')return false;
		if(work[i] == ')' && work[i+1] == '(')return false;
	}

	stack<int> S;
	for(int i = 0; i < length; i++){
		if(work[i] == '(')S.push(i);
		else if(work[i] == ')'){
			if(S.size() == 0)return false;
			else{
				S.pop();
			}
		}
	}
	if(S.size() > 0)return false;

	if(work[0] == '+' || work[0] == '*' || work[0] == '-')return false;

	for(int i = 0; i < length; i++){
		if((work[i] == '0' || work[i] == '1') && work[i+1] == '(')return false;
		if((work[i] == '(') && (work[i+1] == '*' || work[i+1] == '+'))return false;
	}


	int num;
	for(int i = 0; work[i] != '\0';){
		if(work[i] != '0' && work[i] != '1')i++;
		else{
			num = 0;
			for(; (i < length) && (work[i] == '0' || work[i] == '1'); i++){
				num = 2*num+work[i]-'0';
				if(!rangeCheck(num))return false;
			}

		}
	}

	for(int i = 0; work[i] != '\0'; i++){
		if((work[i] == '+' || work[i] == '*' || work[i] == '-') &&
				(work[i+1] == '+' || work[i+1] == '*' || work[i+1] == '-'|| work[i+1] == ')' || work[i+1] == '\0'))return false;
	}

	return true;
}

int calc_E(char line[101],int left,int right){

	int depth = 0;
	queue<int> Q;

	for(int i = left; i <= right; ){
		if(line[i] == '(')depth++;
		else if(line[i] == ')')depth--;

		if(depth != 0){
			i++;
		}else if(line[i] != '+' && line[i] != '-'){
			i++;
		}else{
			if(line[i] == '+'){
				Q.push(i);
				i++;
			}else{ //line[i] == '-'
				if((i != left) && (line[i-1] == '0' || line[i-1] == '1' || line[i-1] == ')')){
					Q.push(i);
				}
				i++;
			}
		}
	}

	if(Q.empty()){
		return calc_T(line,left,right);
	}

	int tmp = calc_E(line,left,Q.front()-1),tmp_right;

	if(tmp == BIG_NUM || rangeCheck(tmp) == false)return BIG_NUM;

	while(!Q.empty()){
		int loc = Q.front();
		Q.pop();

		if(Q.empty()){
			tmp_right = calc_T(line,loc+1,right);
		}else{
			tmp_right = calc_T(line,loc+1,Q.front()-1);
		}

		if(tmp_right == BIG_NUM || rangeCheck(tmp_right) == false){
			return BIG_NUM;
		}

		if(line[loc] == '+'){
			tmp += tmp_right;
		}else{
			tmp -= tmp_right;
		}
		if(rangeCheck(tmp) == false){
			return BIG_NUM;
		}
	}

	return tmp;
}

int calc_T(char line[101],int left,int right){

	int depth = 0;
	queue<int> Q;

	for(int i = left; i <= right; ){
		if(line[i] == '(')depth++;
		else if(line[i] == ')')depth--;

		if(depth != 0){
			i++;
		}else if(line[i] != '*'){
			i++;
		}else{
			Q.push(i);
			i++;
		}
	}

	if(Q.empty()){
		return calc_F(line,left,right);
	}

	int tmp = calc_T(line,left,Q.front()-1),tmp_right;

	if(tmp == BIG_NUM || rangeCheck(tmp) == false)return BIG_NUM;

	while(!Q.empty()){
		int loc = Q.front();
		Q.pop();

		if(Q.empty()){
			tmp_right = calc_F(line,loc+1,right);
		}else{
			tmp_right = calc_F(line,loc+1,Q.front()-1);
		}

		if(tmp_right == BIG_NUM || rangeCheck(tmp_right) == false){
			return BIG_NUM;
		}

		tmp *= tmp_right;
		if(rangeCheck(tmp) == false){
			return BIG_NUM;
		}
	}
	return tmp;
}

int calc_F(char line[101],int left,int right){

	if(line[left] == '1' || line[left] == '0'){
		return calc_NUM(line,left,right);
	}else if(line[left] == '('){

		int depth = 0;
		int close_pos = BIG_NUM;
		bool is_op_exist = false;

		for(int i = left; i <= right; i++){
			if(line[i] == '(')depth++;
			else if(line[i] == ')'){
				depth--;
				if(depth == 0){
					close_pos = i;
					break;
				}
			}else if(line[i] == '+' || line[i] == '-' || line[i] == '*'){
				if(depth == 1){
					is_op_exist = true;
				}
			}
		}

		if(close_pos == BIG_NUM || close_pos != right || is_op_exist == false)return BIG_NUM;

		return calc_E(line,left+1,close_pos-1);
	}else{
		return BIG_NUM;
	}
}

int calc_NUM(char line[101],int left,int right){

	for(int i = left; i <= right; i++){
		if(line[i] != '0' && line[i] != '1')return BIG_NUM;
	}

	int ret = 0;
	for(int i = left; i <= right; i++){
		ret = 2*ret+line[i]-'0';
	}
	return ret;
}


int main(){

	char buf[101];
	scanf("%s",buf);

	vector<int> REPLACE_LOC;
	num_of_blank = 0;

	int length = 0;

	for(int i = 0; buf[i] != '\0'; i++){
		length++;
		if(buf[i] == '.'){
			num_of_blank++;
			REPLACE_LOC.push_back(i);
		}
	}

	int result,ans = -BIG_NUM;

	if(num_of_blank == 0){

		if(!is_OK(buf,length)){
			printf("-1\n");
			return 0;
		}

		result = calc_E(buf,0,length-1);

		if(result == BIG_NUM){
			printf("-1\n");
		}else{
			printf("%d\n",result);
		}
		return 0;
	}

	int first_change_list[5];
	table_index = 0;
	makeTable(first_change_list,0);

	char work[101];

	for(int i = 0; i < table_index; i++){
		for(int k = 0; k < length; k++)work[k] = buf[k];
		work[length] = '\0';

		for(int k = 0; k < num_of_blank; k++){
			work[REPLACE_LOC[k]] = component_array[table[i][k]];
		}

		if(!is_OK(work,length))continue;

		result = calc_E(work,0,length-1);
		if(result == BIG_NUM)continue;

		ans = max(ans,result);
	}

	if(ans == -BIG_NUM){
		printf("-1\n");
	}else{
		printf("%d\n",ans);
	}

	return 0;
}