#include <bits/stdc++.h>
using namespace std;
#define inf (int)(1e9)

int is_num(char c){
  if('0' <= c && c <= '9'){
    return 1;
  }
  else{
    return 0;
  }
}

int eval(string s, int l, int r, int d){
  if(l == 1 && r == s.size() - 1){
//    cout << "-" << s << endl;
  }
  if(d == 5){
    if(s[l] == '(' && s[r-1] == ')') return eval(s, l+1, r-1, 0);
    else{
      int ret = 0;
      for(int i = l;i < r;i++){
        ret *= 10;
        ret += s[i]-'0';
      }
      return ret;
    }
  }
  int cnt = 0;
  for(int i = r-1;i >= l;i--){
    if(s[i] == ')') cnt++;
    else if(s[i] == '(') cnt--;
    if(cnt != 0) continue;
    if(s[i] == '*' && d == 4){
      return eval(s,l,i,d)*eval(s,i+1,r,d+1);
    }else if(s[i] == '+' && d == 3){
      return eval(s,l,i,d)+eval(s,i+1,r,d+1);
    }else if(s[i] == '-' && d == 3){
      return eval(s,l,i,d)-eval(s,i+1,r,d+1);
    }else if(s[i] == '&' && d == 2){
      return eval(s,l,i,d)&eval(s,i+1,r,d+1);
    }else if(s[i] == '^' && d == 1){
      return eval(s,l,i,d)^eval(s,i+1,r,d+1);
    }else if(s[i] == '|' && d == 0){
      return eval(s,l,i,d)|eval(s,i+1,r,d+1);
    }
  }
  int ans = eval(s,l,r,d+1);
//  printf("%d\n", ans);
  return ans;
}

int solve(string s){
  int i, ans = -inf;
  string t;
  for(i = 0; i < s.size() - 1; i++){
    if(is_num(s[i]) == 1 || is_num(s[i + 1]) == 1){
      for(char c = '1'; c <= '9'; c++){
        t = s;
        t.insert(i + 1, 1, c);
        ans = max(ans, eval(t, 1, t.size()-1, 0));
      }
      if(is_num(s[i]) == 1){
        t = s;
        t.insert(i + 1, 1, '0');
        ans = max(ans, eval(t, 1, t.size()-1, 0));
      }
    }
    char ops[] = "*+-&^|";
    if(is_num(s[i]) == 1 && is_num(s[i + 1]) == 1 && s[i + 1] > '0'){
      for(int j = 0; j < 6; j++){
        t = s;
        t.insert(i + 1, 1, ops[j]);
        ans = max(ans, eval(t, 1, t.size()-1, 0));
      }
    }
  }
  for(i = 1; i < s.size() - 1; i++){
    if(is_num(s[i - 1]) == 1 && is_num(s[i + 1]) == 1){
      t = s;
      t.erase(i, 1);
      ans = max(ans, eval(t, 1, t.size()-1, 0));
    }
    if(is_num(s[i]) == 1){
      if(is_num(s[i - 1]) == 1){
        t = s;
        t.erase(i, 1);
        ans = max(ans, eval(t, 1, t.size()-1, 0));
      }
      else if(is_num(s[i + 1]) == 1 && s[i + 1] > '0'){
        t = s;
        t.erase(i, 1);
        ans = max(ans, eval(t, 1, t.size()-1, 0));
      }
    }
  }
  return ans;
}

int solve2(string s){
//  cout << s << endl;
  int i, ans = inf;
  string t;
  for(i = 0; i < s.size() - 1; i++){
    if(is_num(s[i]) == 1 || is_num(s[i + 1]) == 1){
      for(char c = '1'; c <= '9'; c++){
        t = s;
        t.insert(i + 1, 1, c);
        ans = min(ans, eval(t, 1, t.size()-1, 0));
      }
      if(is_num(s[i]) == 1){
        t = s;
        t.insert(i + 1, 1, '0');
        ans = min(ans, eval(t, 1, t.size()-1, 0));
      }
    }
    char ops[] = "*+-&^|";
    if(is_num(s[i]) == 1 && is_num(s[i + 1]) == 1 && s[i + 1] > '0'){
//      printf("test2\n");
      for(int j = 0; j < 6; j++){
        t = s;
        t.insert(i + 1, 1, ops[j]);
        ans = min(ans, eval(t, 1, t.size() - 1, 0));
      }
    }
  }
//  printf("ans = %d\n", ans);
  for(i = 1; i < s.size() - 1; i++){
    if(is_num(s[i - 1]) == 1 && is_num(s[i + 1]) == 1){
      t = s;
      t.erase(i, 1);
      ans = min(ans, eval(t, 1, t.size() - 1, 0));
    }
    if(is_num(s[i]) == 1){
      if(is_num(s[i - 1]) == 1){
        t = s;
//        printf("teeeest\n");
//        cout << t << endl;
        t.erase(i, 1);
//        cout << t << endl;
        ans = min(ans, eval(t, 1, t.size()-1, 0));
      }
      else if(is_num(s[i + 1]) == 1 && s[i + 1] > '0'){
//        printf("test\n");
        t = s;
        t.erase(i, 1);
        ans = min(ans, eval(t, 1, t.size()-1, 0));
      }
    }
  }
//  printf("ans = %d\n", ans);
  return ans;
}

int solve1(string s){
  int i, ans = -inf;
  string t;
  for(i = 0; i < s.size() - 1; i++){
    if(is_num(s[i]) == 1 || is_num(s[i + 1]) == 1){
      for(char c = '1'; c <= '9'; c++){
        t = s;
        t.insert(i + 1, 1, c);
        ans = max(ans, solve2(t));
      }
      if(is_num(s[i]) == 1){
        t = s;
        t.insert(i + 1, 1, '0');
        ans = max(ans, solve2(t));
      }
    }
    char ops[] = "*+-&^|";
    if(is_num(s[i]) == 1 && is_num(s[i + 1]) == 1 && s[i + 1] > '0'){
      for(int j = 0; j < 6; j++){
        t = s;
        t.insert(i + 1, 1, ops[j]);
        ans = max(ans, solve2(t));
      }
    }
  }
  for(i = 1; i < s.size() - 1; i++){
    if(is_num(s[i - 1]) == 1 && is_num(s[i + 1]) == 1){
      t = s;
      t.erase(i, 1);
      ans = max(ans, solve2(t));
    }
    if(is_num(s[i]) == 1){
      if(is_num(s[i - 1]) == 1){
        t = s;
        t.erase(i, 1);
        ans = max(ans, solve2(t));
      }
      else if(is_num(s[i + 1]) == 1 && s[i + 1] > '0'){
        t = s;
        t.erase(i, 1);
        ans = max(ans, solve2(t));
      }
    }
  }
  return ans;
}

int main(){
  while(1){
    int N;
    string s;
    scanf("%d", &N);
    cin >> s;
    if(N == 0){
      return 0;
    }
    s.push_back('#');
    s.insert(0, 1, '#');
    if(N % 2 == 1){
      printf("%d\n", solve(s));
    }
    else{
      printf("%d\n", solve1(s));
    }
  }
}



Measured memory_bytes: 3220