#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;
}



Measured memory_bytes: 3724