#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <stack>
using namespace std;

const int ADD      = 1;
const int SUBTRACT = 2;
const int MULTIPLY = 3;
const int OPEN     = 4;
const int CLOSE    = 5;
const int NUMBER   = 6;
const string C = "01+-*()";

vector<pair<int,int> > S;
int pos;

int fact();
int term();
int exp();

inline void validNum(int n) {
  if(0 <= n && n < (1<<10)) ; else throw "";
}

int fact() {
  int x;
  if(S[pos].first == NUMBER) {
    x = S[pos].second;
    validNum(x);
    ++pos;
  } else if(S[pos].first == OPEN) {
    ++pos;
    x = exp();
    validNum(x);
    if(S[pos].first != CLOSE) throw "";
    ++pos;
  } else {
    throw "";
  }
  return x;
}

int term() {
  int x = fact();
  validNum(x);
  while(S[pos].first == MULTIPLY) {
    ++pos;
    x *= fact();
    validNum(x);
  }
  return x;
}

int exp() {
  int x = term();
  validNum(x);
  while(S[pos].first == ADD || S[pos].first == SUBTRACT) {
    if(S[pos].first == ADD) {
      ++pos;
      x += term();
      validNum(x);
    } else if(S[pos].first == SUBTRACT) {
      ++pos;
      x -= term();
      validNum(x);
    }
  }
  return x;
}

int btod(const string &s) {
  if(s.size() > 31) throw "";
  int res = 0;
  for(int i = 0; i < s.size(); ++i) {
    res = (res << 1);
    if(s[i] == '1') res |= 1;
  }
  return res;
}

bool isValid(const vector<pair<int,int> > &v) {
  stack<int> stk;
  stk.push(0);
  for(int i = 0; i < v.size(); ++i) {
    if(v[i].first == OPEN) {
      stk.push(0);
    } else if(v[i].first == CLOSE) {
      if(stk.size() == 1) return false;
      if(stk.top() == 0) return false;
      stk.pop();
    } else if(v[i].first == NUMBER) {
    } else {
      stk.top() += 1;
    }
  }
  return stk.size() == 1;
}

vector<pair<int,int> > make(const string &s) {
  vector<pair<int,int> > res;
  S.clear();
  for(int i = 0; i < s.size(); ++i) {
    pair<int,int> p;
    if(isdigit(s[i])) {
      string num = "";
      while(isdigit(s[i])) {
        if(num.empty() && s[i] == '0') ; else {
          num += s[i];
        }
        ++i;
      }
      if(num.empty()) num += '0';

      p = make_pair(NUMBER, btod(num));
      --i;
    } else {
      switch(s[i]) {
        case '+': p.first = ADD; break;
        case '-': p.first = SUBTRACT; break;
        case '*': p.first = MULTIPLY; break;
        case '(': p.first = OPEN; break;
        case ')': p.first = CLOSE; break;
      }
    }
    res.push_back(p);
  }
  return res;
}

int main() {
  string s;
  while(cin >> s) {
    vector<int> ind;
    for(int i = 0; i < s.size(); ++i) {
      if(s[i] == '.') ind.push_back(i);
    }
    int res = -1;
    for(int a = 0; a < C.size(); ++a) {
      for(int b = 0; b < C.size(); ++b) {
        for(int c = 0; c < C.size(); ++c) {
          for(int d = 0; d < C.size(); ++d) {
            for(int e = 0; e < C.size(); ++e) {
              if(ind.size() > 0) s[ind[0]] = C[a];
              if(ind.size() > 1) s[ind[1]] = C[b];
              if(ind.size() > 2) s[ind[2]] = C[c];
              if(ind.size() > 3) s[ind[3]] = C[d];
              if(ind.size() > 4) s[ind[4]] = C[e];

              try {
                S = make(s);
                if(isValid(S)) {
                  pos = 0;
                  int tmp = exp();
                  validNum(tmp);
                  if(pos != S.size()) throw "";
                  res = max(res, tmp);
                }
              } catch(const char *error) {}
            }
          }
        }
      }
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1284