#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define Pr(a) (#a)<<"="<<(a)<<" "
#define pr1(a) cerr<<Pr(a)<<endl;
#define pr2(a,b) cerr<<Pr(a)<<Pr(b)<<endl;
#define pr3(a,b,c) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<endl;
#define pr4(a,b,c,d) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<endl;
#define pr5(a,b,c,d,e) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<Pr(e)<<endl;
#define pr6(a,b,c,d,e,f) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<Pr(e)<<Pr(f)<<endl;
#define int long long
#define double long double
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}

class BFN{
public:
  string s;
  int n;
  int pos, valid;
  int rnk[1<<8];
  BFN(){
    memset(rnk,0,sizeof(rnk));
    rnk['*'] = 1;
    rnk['+'] = rnk['-'] = 2;
    rnk['&'] = 3;
    rnk['^'] = 4;
    rnk['|'] = 5;
  }
  
  void Assert(string str = ""){
    valid = 0;
    //cout<<s<<" "<<str<<endl;//assert(0);
  }

  int calc(const string &s){
    this->s = s;
    n = s.size();
    pos = 0;
    valid = 1;
    if(isOperator(S())) Assert("invalid first term");
    if(s.empty()) Assert("empty string");
    if(!valid) return 0;
    int res = bfn();
    if(pos != n) Assert("invalid string");
    return res;
  }

    
  int S(int i=0){
    char res = s[pos];
    pos += i;
    return res;
  }

  int isOperator(int ch){return rnk[ch] != 0;}
  
  int calcOp(int a,int b,char ch){
    if(ch == '*') return a * b;
    if(ch == '+') return a + b;
    if(ch == '-') return a - b;
    if(ch == '&') return a & b;
    if(ch == '^') return a ^ b;
    if(ch == '|') return a | b;
    Assert("invalid operator in calcOP");
  }
  
  int number(){
    assert(isdigit(S()));
    int res = 0;
    if(S() == '0') Assert("invalid number");
    while(pos < n && isdigit(S())) res = res * 10 + S(1) - '0';
    if(res <= 0) Assert("invalid number");
    return res;
  }
  
  int calc(){
    int op = S(1); //今の演算子
    int num = 0;
    if(S() == '(') num = bfn(1);
    else if(isdigit(S())) num = number();
    else Assert("in calc, invalid");
    while(1 && valid){
      if(pos == n) return num;
      int nop = S();//次の演算子
      if(nop != ')' && !isOperator(nop)) Assert("invalid operator in calc()");
      if(nop == ')' || rnk[op] <= rnk[nop]) return num;
      num = calcOp(num,calc(),nop);
    }
  }

  
  int bfn(int depth=0){
    int res;
    if(S() == '(') {pos++;res = bfn(1); pos++;}
    else if(isdigit(S())) res = number();
    else Assert("falid init res in bfn");
    
    while(pos<n && valid){
      if(isOperator(S())) {int op = S(); res = calcOp(res,calc(),op);}
      else if(depth && ')') break;
      else Assert("bfn is not ended by )");
    }
    return res;
  }
};


vector<char> Ch = {'*', '+', '-', '&', '^', '|','0','1','2','3','4','5','6','7','8','9'};

int dfs(string &s,int cnt,int turn){
  BFN A;
  //if(A.calc(s) == 5 && cnt == 0) pr(s,cnt,turn,A.calc(s));
  // pr(s);
  if(cnt == 0) return A.calc(s);
  int n = s.size();
  int res = turn==0? -INF:INF;
  
  //erase    
    for(int i=0;i<n;i++){
      char ch = s[i];
      s.erase(s.begin()+i);
      int a = A.calc(s);
      //if(a == 7) pr(s,cnt,turn,A.valid);
      if(A.valid) {
        if(turn == 0) Max(res, dfs(s, cnt-1, !turn));
        if(turn == 1) Min(res, dfs(s, cnt-1, !turn));
      }
      s.insert(s.begin()+i,ch);
    }

    //insert
    for(int i=0;i<=n;i++){
      for(char ch:Ch){
        s.insert(s.begin()+i,ch);
        int a = A.calc(s);
        //if(a == 7) pr(s,cnt,turn,A.valid);
        if(A.valid){
          if(turn == 0) Max(res, dfs(s, cnt-1, !turn));
          if(turn == 1) Min(res, dfs(s, cnt-1, !turn));
        }
        s.erase(s.begin()+i);
      }
    }
    return res;
}

signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while(1){
    int num;
    string s;
    cin>>num>>s;
    if(num == 0 && s == "#") return 0;
    BFN A; A.calc(s);
    assert(A.valid == 1);
    
    int ans = -1;
    if(num%2 == 1){ans = dfs(s,min(num,1LL),0);}
    if(num%2 == 0){ans = dfs(s,min(num,2LL),0);}
    cout<<ans<<endl;
  }

  
  return 0;
}



Measured memory_bytes: 3252