#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;

struct BNF{
  string s;
  int p,n;
  set<int>st;
  BNF(string t){
    s=t;
    p=0;
    n=t.size();
  }
  int get_A(){
    int res=0;
    if(s[p]=='(')p++,res=bnf1(),p++;
    else{
      while(isdigit(s[p]))res=res*10+(s[p]-'0'),p++;
      st.insert(res);
    }
    return res;
  }
  int bnf1(){
    int res=bnf2();
    while(s[p]=='|'){
      int t=p++;
      res|=bnf2();
    }
    return res;
  }
  int bnf2(){
    int res=bnf3();
    while(s[p]=='^'){
      int t=p++;
      res^=bnf3();
    }
    return res;
  }
  int bnf3(){
    int res=bnf4();
    while(s[p]=='&'){
      int t=p++;
      res&=bnf4();
    }
    return res;
  }
  int bnf4(){
    int res=bnf5();
    while(s[p]=='+'||s[p]=='-'){
      int t=p++;
      if(s[t]=='+')res+=bnf5();
      if(s[t]=='-')res-=bnf5();
    }
    return res;
  }
  int bnf5(){
    int res=get_A();
    while(s[p]=='*'){
      int t=p++;
      res*=get_A();
    }
    return res;
  }
  
  int build(){
    p=0;
    int x= bnf1();
    if(st.size()==1&&*st.begin()==0)return 1e18;
    return x;
  }
};

char ca[]={'+','-','&','|','^','*'};
int na[]={1,2,3,4,5,6,7,8,9};

int solve2(int n,string s){//if(s=="(5^3)")cout<<s<<endl;
  int N=s.size();
  int ans=1e18;

  for(int i=0;i<N;i++){
    string t=s;
    if(isdigit(s[i])){
      int f=0;
      for(int j=0;j<9;j++){
   t=s;
   t=t.substr(0,i)+(char(na[j]+'0'))+t.substr(i);
   BNF B(t);if(t=="0")continue;
   ans=min(ans,B.build());//if(s=="(5^3)")cout<<t<<endl;
   t=s;
   t=t.substr(0,i+1)+(char(na[j]+'0'))+t.substr(i+1);
   BNF B1(t);if(t=="0")continue;//if(s=="(508^3)")cout<<t<<endl;
   ans=min(ans,B1.build());//if(s=="(5^3)")cout<<t<<endl;
      }
      t=s;
   t=t.substr(0,i+1)+(char(0+'0'))+t.substr(i+1);
   BNF B1(t);if(t=="0")continue;//if(s=="(508^3)")cout<<t<<endl;
   ans=min(ans,B1.build());//if(s=="(5^3)")cout<<t<<endl;
   t=s;
      if(i!=N-1&&isdigit(s[i+1]))f++;
      if(i!=0&&isdigit(s[i-1]))f++;
      if(!f)continue;
      int o=0;
      if(i!=0&&isdigit(s[i-1]))o=1;
      for(int k=i+1;k<N;k++){
        if(isdigit(s[k])&&s[k]!='0')o++;
        else break;
      }
      if(!o)continue;
      string t=s;
      // cout<<t<<endl;2 7537901
      t.erase(t.begin()+i);//if(s=="5|3^4*80") cout<<t<<endl;
      //if(s=="80")cout<<t<<endl;
      //if(s=="(80*5)")cout<<t<<endl;
      BNF B(t);//if(s=="(508^3)")cout<<t<<endl;
      //if(t=="0")continue;
      //if(s=="(508^3)")cout<<B.build()<<endl;
      //if(s=="(5^3)")cout<<t<<endl;
      ans=min(ans,B.build());
    }
    t=s;
    if(t[i]!='('&&t[i]!=')'){
      if(i!=0){
        if(isdigit(s[i])&&isdigit(s[i-1])&&s[i]!='0'){
          for(int j=0;j<6;j++){
            t=s;
            t=t.substr(0,i)+(char(ca[j]))+t.substr(i);
            BNF B(t);//if(t=="0")continue;//if(s=="80")cout<<t<<endl;
          //if(s=="(508^3)")cout<<t<<endl;
      //cout<<t<<endl;
            ans=min(ans,B.build());//if(s=="(5^3)")cout<<t<<endl;
            //if(s=="(508^3)")cout<<B.build()<<endl;
      //cout<<ans<<endl;
          }
        }
      }
      int f=0;
      /*if(i!=N-1&&isdigit(s[i+1]))f++;
      if(i!=0&&isdigit(s[i-1]))f++;
      if(!f)continue;*/
      if(!(isdigit(s[i-1])&&isdigit(s[i+1])))continue;
      
      t=s;
      //cout<<t<<endl;
      t.erase(t.begin()+i);//if(s=="5|3^4*80") cout<<t<<endl;
      BNF A(t);if(t=="0")continue;//if(s=="80")cout<<t<<endl;
      //if(s=="(508^3)")cout<<t<<endl;
      ans=min(ans,A.build());//if(s=="(5^3)")cout<<t<<endl;
      //if(s=="(508^3)")cout<<t<<endl;
      //if(s=="(508^3)")cout<<B.build()<<endl;
      //cout<<A.build()<<endl;
    }
    
  }//if(s=="5|3^4*80")cout<<ans<<endl;
  if(ans==1e18)ans=-1e18;
  //cout<<"         "<<s<<' '<<ans<<endl;
  //cout<<ans<<endl;
  //if(s=="(5^3)")cout<<ans<<endl;
  return ans;
}

void solve(int n,string s){

  int N=s.size();

  int ans=-1e18;
  
  if(n%2){
    for(int i=0;i<N;i++){//cout<<i<<endl;
      string t=s;
      int o=0;
      if(isdigit(t[i])){
     /* if(i!=0&&isdigit(s[i-1]))o=1;
      for(int k=i;k<N;k++){
        if(isdigit(s[k])&&s[k]!='0')o++;
        else if(!isdigit(s[k]))break;
      }//cout<<o<<endl;
      if(o){
      t=s;
      // cout<<t<<endl;2 7537901
      t.erase(t.begin()+i);//if(s=="5|3^4*80") cout<<t<<endl;
      //if(s=="80")cout<<t<<endl;
      //if(s=="(80*5)")cout<<t<<endl;
      BNF B(t);//if(s=="(508^3)")cout<<t<<endl;
      //if(t=="0")continue;
      //if(s=="(508^3)")cout<<B.build()<<endl;
      //if(s=="(5^3)")cout<<t<<endl;
      ans=max(ans,solve2(n,t));}*/
      t=s;
  for(int j=0;j<9;j++){
    t=s;
    t=t.substr(0,i)+(char(na[j]+'0'))+t.substr(i);
    BNF B(t);
    //cout<<t<<endl;
     ans=max(ans,B.build());
     //cout<<B.build()<<endl;
    t=s;
    t=t.substr(0,i+1)+(char(na[j]+'0'))+t.substr(i+1);
    BNF B1(t);
    //cout<<t<<endl;
    ans=max(ans,B1.build());
    //cout<<B1.build()<<endl;
  }
  t=s;
   t=t.substr(0,i+1)+(char(0+'0'))+t.substr(i+1);
   BNF B1(t);
   ans=max(ans,B1.build());
   t=s;
      }
      t=s;
      if(t[i]!='('&&t[i]!=')'){
        if(i!=0){
    if(isdigit(s[i])&&isdigit(s[i-1]&&s[i]!='0')){
      for(int j=0;j<6;j++){
        t=s;
        t=t.substr(0,i)+(char(ca[j]))+t.substr(i);
        BNF B(t);
        ans=max(ans,B.build());
      }
    }
  }
  int f=0;
  /*if(i!=N-1&&isdigit(s[i+1]))f++;
  if(i!=0&&isdigit(s[i-1]))f++;
  if(!f)continue;*//*if(i==N-2&&s[i+1]=='0')continue;
      if(i<N-2&&s[i+1]=='0'&&!isdigit(s[i+2]))continue;*/

  
  if(!(isdigit(s[i-1])&&isdigit(s[i+1])))continue;
  t=s;
  t.erase(t.begin()+i);
  BNF A(t);
  ans=max(ans,A.build());
      }
      
    }
  }
  else{
    for(int i=0;i<N;i++){
      string t=s;
      if(isdigit(t[i])){
        int o=0;
         if(i!=0&&isdigit(s[i-1]))o=1;
        for(int k=i;k<N;k++){
            if(isdigit(s[k])&&s[k]!='0')o++;
            else if(!isdigit(s[k]))break;
        }//cout<<o<<endl;
        if(i==0&&!isdigit(s[i+1]))o=0;
        if(i==N-1&&!isdigit(s[i-1]))o=0;
        if(i!=0&&i!=N-1&&!isdigit(s[i-1])&&!isdigit(s[i+1]))o=0;
        if(o){
        t=s;
      // cout<<t<<endl;2 7537901
        t.erase(t.begin()+i);//if(s=="5|3^4*80") cout<<t<<endl;
      //if(s=="80")cout<<t<<endl;
      //if(s=="(80*5)")cout<<t<<endl;
        BNF B(t);//if(s=="(508^3)")cout<<t<<endl;
      //if(t=="0")continue;
      //if(s=="(508^3)")cout<<B.build()<<endl;
      //if(s=="(5^3)")cout<<t<<endl;
        ans=max(ans,solve2(n,t));}
        t=s;
  for(int j=0;j<9;j++){
    t=s;
    t=t.substr(0,i)+(char(na[j]+'0'))+t.substr(i);
    BNF B(t);
    //cout<<t<<endl;
    ans=max(ans,solve2(n,t));
    // cout<<ans<<endl;
    t=s;
    t=t.substr(0,i+1)+(char(na[j]+'0'))+t.substr(i+1);
    BNF B1(t);
    // cout<<t<<endl;
    ans=max(ans,solve2(n,t));
    //cout<<ans<<endl;
  }
  t=s;
   t=t.substr(0,i+1)+(char(0+'0'))+t.substr(i+1);
   BNF B1(t);
   ans=max(ans,solve2(n,t));
   t=s;
      }
      t=s;
      if(t[i]!='('&&t[i]!=')'){
        if(i!=0){
    if(isdigit(s[i])&&isdigit(s[i-1])&&s[i]!='0'){
      for(int j=0;j<6;j++){
        t=s;
        t=t.substr(0,i)+(char(ca[j]))+t.substr(i);
        // BNF B(t);
        //cout<<t<<endl;
        ans=max(ans,solve2(n,t));
        // cout<<ans<<endl;
      }
    }
  }
  int f=0;
  /*if(i==N-2&&s[i+1]=='0')continue;
      if(i<N-2&&s[i+1]=='0'&&!isdigit(s[i+2]))continue;*/
        if(!(isdigit(s[i-1])&&isdigit(s[i+1])))continue;
  t=s;
  t.erase(t.begin()+i);
  //BNF A(t);
  //cout<<t<<endl;
  ans=max(ans,solve2(n,t));
  //cout<<ans<<endl;
      }
      
    }
    
  }
  cout<<ans<<endl;
}

signed main(){
  int n;
  string s;
  while(cin>>n>>s){
    if(n==0&&s[0]=='#')break;
    solve(n,s);
  }
}
