#include <iostream>
#include <sstream>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <numeric>
#include <bitset>
#include <stack>
#include <cstring>
using namespace std;

const int INF = 1 << 30;
const double EPS = 1e-10;

const string OP = "01+-*()";

int expression(const string& s, unsigned int& p);

bool valid(const int n)
{
  if (n < 0 || 1024 <= n)
    return false;
  return true;
}

int number(const string& s, unsigned int& p)
{
  int ret = 0;
  while (s[p] == '0' || s[p] == '1') {
    ret *= 2;
    ret += (s[p] - '0');
    ++p;
  }
  return ret;
}

int factor(const string& s, unsigned int& p)
{
  if (s[p] == '(') {
    ++p;
    int ret = expression(s, p);
    if (!valid(ret) || s[p] != ')')
      return -1;
    ++p;
    return ret;
  } else if (s[p] == '0' || s[p] == '1') {
    return number(s, p);
  } else {
    return -1;
  }
}

int term(const string& s, unsigned int& p)
{
  int lhs = factor(s, p);
  if (!valid(lhs))
    return -1;

  while (p < s.size()) {
    if (s[p] == '*') {
      ++p;
      int rhs = factor(s, p);
      if (!valid(rhs) || !valid(lhs*rhs))
        return -1;
      lhs *= rhs;
    } else {
      break;
    }
  }
  return lhs;
}

int expression(const string& s, unsigned int& p)
{
  int lhs = term(s, p);
  if (!valid(lhs))
    return -1;

  while (p < s.size()) {
    if (s[p] == '+') {
      ++p;
      int rhs = term(s, p);
      if (!valid(rhs) || !valid(lhs+rhs))
        return -1;
      lhs += rhs;
    } else if (s[p] == '-') {
      ++p;
      int rhs = term(s, p);
      if (!valid(rhs) || !valid(lhs-rhs))
        return -1;
      lhs -= rhs;
    } else {
      break;
    }
  }
  return lhs;
}

bool check(const string& s)
{
  int par = 0;
  char prev = '\0';
  deque<bool> op(100, false);

  for (unsigned int i = 0; i < s.size(); ++i) {
    if (prev == '\0') {
      if (s[i] == '(') {
        ++par;
        prev = s[i];
      } else if (s[i] == '0' || s[i] == '1') {
        prev = s[i];
      } else {
        return false;
      }
    } else if (prev == '(') {
      if (s[i] == '0' || s[i] == '1') {
        prev = s[i];
      } else if (s[i] == '(') {
        ++par;
        prev = s[i];
      } else {
        return false;
      }
    } else if (prev == '0' || prev == '1') {
      if (s[i] == '(')
        return false;

      if (s[i] == ')') {
        if (par < 0 || !op[par])
          return false;
        op[par] = false;
        --par;
      }
      prev = s[i];
    } else if (prev == '+' || prev == '-' || prev == '*') {
      if (par > 0)
        op[par] = true;
      if (s[i] == '0' || s[i] == '1') {
        prev = s[i];
      } else if (s[i] == '(') {
        ++par;
        prev = s[i];
      } else {
        return false;
      }
    } else if (prev == ')') {
      if (s[i] == '+' || s[i] == '-' || s[i] == '*') {
        prev = s[i];
      } else if (s[i] == ')') {
        if (par < 0 || !op[par])
          return false;
        op[par] = false;
        --par;
      } else {
        return false;
      }
    }
  }

  if (par == 0)
    return true;
  return false;
}

int solve(unsigned int idx, string& s)
{
  if (idx >= s.size()) {
    if (!check(s))
      return -1;
    idx = 0;
    return expression(s, idx);
  }

  if (s[idx] == '.') {
    int ret = -INF;
    for (unsigned int i = 0; i < OP.size(); ++i) {
      s[idx] = OP[i];
      ret = max(ret, solve(idx+1, s));
      s[idx] = '.';
    }
    return ret;
  } else {
    return solve(idx+1, s);
  }
}

int main()
{
  string s;
  while (cin >> s)
    cout << solve(0, s) << endl;
  return 0;
}