#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <valarray>
#include <bitset>
#include <cassert>
#include <climits>
#include <cstring>
#include <sstream>
using namespace std;

#define REP(i,n) for(int i=0; i<(int)n; ++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-9;
const char ZERO = '0';
const char ONE = '1';
const int MAX_VAL = (1<<10) - 1;
const int MIN_VAL = 0;

inline bool isOp(char c) {
  return c == '*' || c == '-' || c == '+';
}

typedef pair<int, int> value;
const value ERROR = make_pair(-1,-1);

value mult_exp(const string &s,int idx=0);
value number(const string &s,int idx =0);
value prim_exp(const string &s,int idx=0);

value add_exp(const string &s,int idx) {
  if(s[idx] != ONE && s[idx] != ZERO && s[idx] != '(') return ERROR;
  value left = mult_exp(s, idx);
  idx = left.second;
  int v = left.first;
  while(true) {
    if (idx < s.length() && (s[idx] == '+' || s[idx] == '-')) {
      char op = s[idx];
      value right = mult_exp(s,idx+1);
      if (right == ERROR) return ERROR;
      switch(op) {
      case '+':
	v += right.first;
	break;
      case '-':
	v -= right.first;
	break;
      }
      if (v < MIN_VAL || v > MAX_VAL) return ERROR;
      idx = right.second;
    }else break;
  }
  return make_pair(v, idx);
}

value mult_exp(const string &s,int idx) {
  if(s[idx] != ONE && s[idx] != ZERO && s[idx] != '(') return ERROR;

  value left = prim_exp(s,idx);
  if (left == ERROR) return ERROR;
  idx = left.second;
  int v = left.first;
  while(true) {
    if (idx < s.length() && s[idx] == '*') {
      value right = prim_exp(s, idx+1);
      if (right == ERROR) return ERROR;
      v *= right.first;
      if (v < MIN_VAL || v > MAX_VAL) return ERROR;
      idx = right.second;
    } else break;
  }

  return make_pair(v, idx);
}

value prim_exp (const string &s, int idx) {
  if (s[idx] == ONE || s[idx] == ZERO) return number(s,idx);
  if (s[idx] != '(') return ERROR;
  value v = add_exp(s, idx+1);
  if (v.second >= s.length() || s[v.second] != ')' || v == ERROR) return ERROR;
  if (v.first < MIN_VAL || v.second > MAX_VAL) return ERROR;

  bool onlynum = true;
  for (int i=idx+1; i<v.second; ++i) {
    if(s[i] != ONE && s[i] != ZERO) onlynum = false;
  }
  if(onlynum) return ERROR;
  return make_pair(v.first, v.second+1);
}

value number(const string &s, int idx) {
  if (s[idx] != ONE && s[idx] != ZERO) return ERROR;
  int ret = 0;
  while(s[idx] == ONE || s[idx] == ZERO) {
    ret <<= 1;
    ret += s[idx] - ZERO;
    if (ret < MIN_VAL || ret > MAX_VAL) return ERROR;
    idx++;
    if(idx == s.length()) break;
  }
  //cout<<"number:"<<ret<<endl;
  if (ret < MIN_VAL || ret > MAX_VAL) return ERROR;
  return make_pair(ret, idx);
}

char letter[7] = {'0', '1', '+', '-', '*', '(', ')'};

bool check(const string &in) {
  bool ok = true;
  for (int i=0; i<in.length(); ++i) {
    if(in[i] != '(') continue;
    int depth = 1, nop = 0;
    for (int j=i+1; j<in.length(); ++j) {
      if(in[j] == '(') depth++;
      if(in[j] == ')') depth--;
      if(depth == 0) break;
      if(depth == 1 && (in[j] == '+' || in[j] == '-' || in[j] == '*')) {
	nop++;
      }
    }
    if(nop == 0) ok = false;
  }
  return ok;
}

int main() {
  string input;
  cin>>input;
  char cnt = '2';
  for (int i=0; i<input.length(); ++i) {
    if (input[i] == '.') input[i] = cnt++;
  }

  int num = cnt - '2';

  if(num == 0) {
    value v = add_exp(input, 0);
    if(v == ERROR
       || !check(input)
       || v.second != input.length()) cout<<-1<<endl;
    else cout<<v.first<<endl;
    return 0;
  }

  vector<int> pattern(num, 0);
  int ans = -1;
  while(true) {
    string in = input;
    for (int i=0; i<in.length(); ++i) {
      if(in[i] >= '2' && in[i] <= '9') in[i] = letter[pattern[in[i]-'2']];
    }

    value v = add_exp(in,0);
    if(v != ERROR && v.second == in.length() && check(in)) {
        //if(ans < v.first) cout<<in<<endl;
      ans = max(ans, v.first);
    }

    bool end = true;
    for (int i=0; i<num; ++i)
      if(pattern[i] != 6) end = false;
    if(end) break;

    for (int i=0; i<num; ++i) {
      if(pattern[i] == 6) pattern[i] = 0;
      else {
	pattern[i]++;
	break;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1192