#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

int N;
string s,t;
int cur;

int exp6();

int digit(){
	assert(isdigit(s[cur]));
	return s[cur++]-'0';
}

int num(){
	int res=0;
	while(isdigit(s[cur])){
		res=res*10+digit();
	}
	return res;
}

int exp1(){
	if(isdigit(s[cur])){
		return num();
	}
	assert(s[cur]=='(');
	cur++;
	int res=exp6();
	assert(s[cur]==')');
	cur++;
	return res;
}

int exp2(){
	int res=exp1();
	while(s[cur]=='*'){
		cur++;
		res *= exp1();
	}
	return res;
}

int exp3(){
	int res=exp2();
	while(s[cur]=='+' || s[cur]=='-'){
		if(s[cur]=='+'){
			cur++;
			res += exp2();
		}else{
			cur++;
			res -= exp2();
		}
	}
	return res;
}

int exp4(){
	int res=exp3();
	while(s[cur]=='&'){
		cur++;
		res &= exp3();
	}
	return res;
}

int exp5(){
	int res=exp4();
	while(s[cur]=='^'){
		cur++;
		res ^= exp4();
	}
	return res;
}

int exp6(){
	int res=exp5();
	while(s[cur]=='|'){
		cur++;
		res |= exp5();
	}
	return res;
}

string ops="*+-&^|";

int f(string t,int turn){
	int res;
	if(turn==0)res=-INF;
	else res=INF;
	if(turn==1);//cerr<<t<<" -> "<<endl;
	rep(i,sz(t)-1){
		if(isdigit(t[i]) || isdigit(t[i+1])){
			for(char d='0';d<='9';d++){
				if(d=='0' && !isdigit(t[i]))continue;
				s=t.substr(0,i+1) + d + t.substr(i+1);
				cur=1;
				if(turn==0){
					if(N==1)res=max(res,exp6());
					else res=max(res,f(s,1));
				}else res=min(res,exp6());
				if(turn==1);//cerr<<s<<endl;
			}
		}
		if(isdigit(t[i]) && isdigit(t[i+1])){
			if(t[i+1]=='0')continue;
			rep(j,sz(ops)){
				s=t.substr(0,i+1) + ops[j] + t.substr(i+1);
				cur=1;
				if(turn==0){
					if(N==1)res=max(res,exp6());
					else res=max(res,f(s,1));
				}else res=min(res,exp6());
				if(turn==1);//cerr<<s<<endl;
			}
		}
	}
	rep2(i,1,sz(t)-1){
		if(isdigit(t[i])){
			if(!isdigit(t[i-1]) && !isdigit(t[i+1])
			|| !isdigit(t[i-1]) && t[i+1]=='0'){
				continue;
			}
			s=t.substr(0,i)+t.substr(i+1);
			cur=1;
			if(turn==0){
				if(N==1)res=max(res,exp6());
				else res=max(res,f(s,1));
			}else res=min(res,exp6());
			if(turn==1);//cerr<<s<<endl;
		}
		else{
			if(!(isdigit(t[i-1]) && isdigit(t[i+1]))){
				continue;
			}
			s=t.substr(0,i)+t.substr(i+1);
			cur=1;
			if(turn==0){
				if(N==1)res=max(res,exp6());
				else res=max(res,f(s,1));
			}else res=min(res,exp6());
			if(turn==1);//cerr<<s<<endl;
		}
	}
	if(turn==1){
		;//cerr<<t<<" : "<<res<<endl;
	}
	return res;
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	while(cin>>N>>t && N){
		t=" "+t+" ";
		if(N%2==1)N=1;
		else N=2;
		cout<<f(t,0)<<endl;
	}
}

Measured memory_bytes: 1228