#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
bool isd(string s){return isdigit(s[0]);}

string calc(vs s){
    stack<int> p;
    for(int i=0;i<s.size();i++){
        if(s[i]=="(")p.push(i);
        else if(s[i]==")"){
            int f=p.top(); p.pop();
            vs tmp;
            s[f]=s[i]="-1";
            for(int j=f+1;j<i;j++){
                tmp.pb(s[j]);
                s[j]="-1";
            }
            s[f]=calc(tmp);
            if(s[f]=="-1") return "-1";
            //cout<<"ans"<<s[f]<<endl;
        }
    }
    //for(auto c:s)cout<<setw(3)<<c;cout<<endl;
    auto itr=remove(all(s),"-1");
    s.erase(itr,s.end());
    if(s.size()==0)return "-1";
    //for(auto c:s)cout<<c<<"      ";
    
    deque<int> oper;
    deque<string> opec;
    for(int i=0;i<s.size();i++){
        if(isd(s[i])){
            oper.pb(stoi(s[i]));
        }else{
            if(s[i]=="*"){
                oper.back()*=stoi(s[++i]);
                if(oper.back()<0 || oper.back()>1023) return "-1";
            }else opec.pb(s[i]);
        }
    }
    while(!opec.empty()){
        int d=oper[0];
        string c=opec[0];
        oper.pop_front();
        opec.pop_front();
        oper.front()=(c=="+" ? d+oper.front() : d-oper.front());
        if(oper.front()<0 || oper.front()>1023) return "-1";
    }
    return to_string(oper[0]);
}


string solve(string in){
    vector<string> s;
    bool ren=false;
    for(auto c:in){
        if(c=='0' || c=='1'){
            if(ren){
                s.back()+=c;
            }else s.pb(""s+c);
            ren=true;
        } else {
            s.pb(""s+c);
            ren=false;
        }
    }

    int dep=0;
    for(int i=0;i<s.size();i++){
        string &c=s[i];
        try{
            int p=stoi(c,nullptr,2);
            if(p>1023) return "-1";
            c=to_string(p);
        }catch(std::invalid_argument){
            if(c=="(")dep++;
            else if(c==")")dep--;
            if(dep<0 || dep>25)return "-1";
        }catch(...){
            return "-1";
        }
    }
    if(dep)return "-1";

    //for(auto c:s)cout<<c;cout<<endl;
    int exist=0,depth=0;
    for(int i=0;i<s.size()-1;i++){
        if(isd(s[i])){
            if(s[i+1]=="(" || isd(s[i+1])) return "-1";
        }else if(s[i]=="("){
            depth++;
            if(s[i+1]=="+" || s[i+1]=="-" || s[i+1]=="*" || s[i+1]==")") return "-1";
        }else if(s[i]==")"){
            //cout<<depth<<","<<exist<<endl;
            if((exist&(1<<depth))==0) return "-1";
            //cout<<"OK"<<endl;
            exist&=~(1<<depth);
            depth--;
            if(isd(s[i+1]) || s[i+1]=="(") return "-1";
        }else{
            exist|=(1<<depth);
            if(s[i+1]!="(" && !isd(s[i+1])) return "-1";
        }
    }

    if(s.back()==")"){
        if((exist&(1<<depth))==0) return "-1";
    }
    int t=s.size()-1;
    if(s[0]==")" || s[0]=="+" || s[0]=="-" || s[0]=="*") return "-1";
    if(s[t]=="(" || s[t]=="+" || s[t]=="-" || s[t]=="*") return "-1";

    //ここまでで除去ができているはず
    //for(auto c:s)cout<<c;cout<<endl;
    string ans=calc(s);
    //cout<<"="<<ans<<endl;
    return ans;
}

int bur(string s){
    int ans=-1;
    if(count(all(s),'.')==0) {
        return stoi(solve(s));
    }
    for(auto d:"01+-*()"s){
        string os=s;
        os[s.find('.')]=d;
        ans=max(ans,bur(os));
    }
    return ans;
}

int main(){
    string o;
    cin>>o;
    cout<<bur(o)<<endl;
	return 0;
}



Measured memory_bytes: 3440