#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 20
#define SIZE 16

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

ll calc_EXP(char line[NUM],int left,int right);
ll calc_OR(char line[NUM],int left,int right);
ll calc_XOR(char line[NUM],int left,int right);
ll calc_AND(char line[NUM],int left,int right);
ll calc_PLUS_MINUS(char line[NUM],int left,int right);
ll calc_MULT(char line[NUM],int left,int right);
ll getNUM(char line[NUM],int left,int right);


//指定された範囲で、深さ0のopを探す関数
queue<int> find_op(char op,char line[NUM],int left,int right){

	queue<int> RET;

	int depth = 0;

	for(int i = left; i <= right; ){
		if(line[i] == '(')depth++;
		else if(line[i] == ')')depth--;

		if(depth != 0){
			i++;
		}else{

			if((line[i] == op) || ((line[i] == '+' || line[i] == '-') && op == '@')){ //@:+または-
				RET.push(i);
				i++;
			}else{ //単項演算子なし
				i++;
			}
		}
	}

	return RET;
}

ll getNUM(char line[NUM],int left,int right){

	if(left > right){
		return HUGE_NUM;
	}

	//left～righgtの間に、非数字があったら誤り
	for(int i = left; i <= right; i++){
		if(line[i] < '0' || line[i] > '9'){
			return HUGE_NUM;
		}
	}

	if(line[left] == '0'){ //正の数でなければ不可
		return HUGE_NUM;
	}

	ll ret = 0;

	for(int i = left; i <= right; i++){
		ret = 10*ret+(line[i]-'0');
	}

	return ret;
}

ll calc_MULT(char line[NUM],int left,int right){

	if(left > right){
		return HUGE_NUM;
	}

	ll tmp;

	if(line[left] == '('){

		if(line[right] != ')'){
			return HUGE_NUM;
		}

		tmp = calc_EXP(line,left+1,right-1);

	}else if(line[left] >= '0' && line[left] <= '9'){ //数字

		tmp = getNUM(line,left,right);

	}else{ //文法誤り
		return HUGE_NUM;
	}

	return tmp;
}

ll calc_PLUS_MINUS(char line[NUM],int left,int right){

	if(left > right){
		return HUGE_NUM;
	}

	queue<int> Q = find_op('*',line,left,right);

	if(Q.empty()){
		return calc_MULT(line,left,right);
	}

	ll tmp = calc_PLUS_MINUS(line,left,Q.front()-1),tmp_right;

	if(tmp == HUGE_NUM)return HUGE_NUM;

	while(!Q.empty()){
		int loc = Q.front();
		Q.pop();

		if(Q.empty()){
			tmp_right = calc_MULT(line,loc+1,right);
		}else{
			tmp_right = calc_MULT(line,loc+1,Q.front()-1);
		}

		if(tmp_right == HUGE_NUM){
			return HUGE_NUM;
		}

		tmp *= tmp_right;
	}
	return tmp;
}

ll calc_AND(char line[NUM],int left,int right){

	if(left > right){
		return HUGE_NUM;
	}

	queue<int> Q = find_op('@',line,left,right);

	if(Q.empty()){
		return calc_PLUS_MINUS(line,left,right);
	}

	ll tmp = calc_AND(line,left,Q.front()-1),tmp_right;

	if(tmp == HUGE_NUM)return HUGE_NUM;

	while(!Q.empty()){
		int loc = Q.front();
		Q.pop();

		if(Q.empty()){
			tmp_right = calc_PLUS_MINUS(line,loc+1,right);
		}else{
			tmp_right = calc_PLUS_MINUS(line,loc+1,Q.front()-1);
		}

		if(tmp_right == HUGE_NUM){
			return HUGE_NUM;
		}

		if(line[loc] == '+'){
			tmp += tmp_right;
		}else{
			tmp -= tmp_right;
		}
	}
	return tmp;
}

ll calc_XOR(char line[NUM],int left,int right){

	if(left > right){
		return HUGE_NUM;
	}

	queue<int> Q = find_op('&',line,left,right);

	if(Q.empty()){
		return calc_AND(line,left,right);
	}

	ll tmp = calc_XOR(line,left,Q.front()-1),tmp_right;

	if(tmp == HUGE_NUM)return HUGE_NUM;

	while(!Q.empty()){
		int loc = Q.front();
		Q.pop();

		if(Q.empty()){
			tmp_right = calc_AND(line,loc+1,right);
		}else{
			tmp_right = calc_AND(line,loc+1,Q.front()-1);
		}

		if(tmp_right == HUGE_NUM){
			return HUGE_NUM;
		}

		tmp &= tmp_right;
	}
	return tmp;
}

ll calc_OR(char line[NUM],int left,int right){

	if(left > right){
		return HUGE_NUM;
	}

	queue<int> Q = find_op('^',line,left,right);

	if(Q.empty()){
		return calc_XOR(line,left,right);
	}

	ll tmp = calc_OR(line,left,Q.front()-1),tmp_right;

	if(tmp == HUGE_NUM)return HUGE_NUM;

	while(!Q.empty()){
		int loc = Q.front();
		Q.pop();

		if(Q.empty()){
			tmp_right = calc_XOR(line,loc+1,right);
		}else{
			tmp_right = calc_XOR(line,loc+1,Q.front()-1);
		}

		if(tmp_right == HUGE_NUM){
			return HUGE_NUM;
		}

		tmp ^= tmp_right;
	}
	return tmp;
}

bool is_op(char ch){
	if(ch == '|' || ch == '^' || ch == '&' || ch == '+' || ch == '-' || ch == '*'){
		return true;
	}else{
		return false;
	}
}


ll calc_EXP(char line[NUM],int left,int right){

	if(right < left){
		return HUGE_NUM;
	}

	//left～rightの区間にある、orを探す
	queue<int> Q = find_op('|',line,left,right);

	//深さ0のorがない
	if(Q.empty()){
		return calc_OR(line,left,right);
	}

	ll tmp = calc_EXP(line,left,Q.front()-1),tmp_right;

	if(tmp == HUGE_NUM)return HUGE_NUM;

	while(!Q.empty()){
		int loc = Q.front();
		Q.pop();

		if(Q.empty()){
			tmp_right = calc_OR(line,loc+1,right);
		}else{
			tmp_right = calc_OR(line,loc+1,Q.front()-1);
		}

		if(tmp_right == HUGE_NUM){
			return HUGE_NUM;
		}

		tmp |= tmp_right;
	}
	return tmp;
}

void add_char(char line[NUM],int length,int loc,char ch){

	if(loc == length){
		line[loc] = ch;
		return;
	}

	queue<char> Q;
	for(int i = loc; i < length; i++){
		Q.push(line[i]);
	}
	line[loc] = ch;

	int index = loc+1;

	while(!Q.empty()){

		line[index++] = Q.front();
		Q.pop();
	}
}

void del_char(char line[NUM],int length,int loc){

	for(int i = loc+1; i < length; i++){
		line[i-1] = line[i];
	}
}

void copy_line(char line[NUM],char base[NUM],int length){

	for(int i = 0; i < length; i++){
		line[i] = base[i];
	}
}

void func(char buf[NUM]){

	int length;
	for(length = 0; buf[length] != '\0'; length++);


	ll tmp,ans;

	char work[NUM];

	if(N%2 == 1){ //結果を最大化する

		ans = -HUGE_NUM;

		//1文字加える
		for(int loc = 0; loc <= length; loc++){
			for(int i = 0; i < SIZE; i++){
				copy_line(work,buf,length);
				add_char(work,length,loc,add[i]);
				tmp = calc_EXP(work,0,length);
				if(tmp == HUGE_NUM)continue;

				ans = max(ans,tmp);
			}
		}

		//1文字削る
		for(int loc = 0; loc <= length-1; loc++){
			copy_line(work,buf,length);
			del_char(work,length,loc);
			tmp = calc_EXP(work,0,length-2);
			if(tmp == HUGE_NUM)continue;

			ans = max(ans,tmp);
		}

	}else{ //先手が2ターン全探索した最良値を選ぶはず

		ans = -HUGE_NUM;
		char gote_work[NUM];
		ll tmp_ans,result;

		//先手が1文字加える
		for(int loc = 0; loc <= length; loc++){
			for(int i = 0; i < SIZE; i++){

				copy_line(work,buf,length);
				add_char(work,length,loc,add[i]);
				tmp = calc_EXP(work,0,length);
				if(tmp == HUGE_NUM)continue;

				tmp_ans = HUGE_NUM;

				//後手が1文字加える
				for(int gote_loc = 0; gote_loc <= length+1; gote_loc++){
					for(int k = 0; k < SIZE; k++){
						copy_line(gote_work,work,length+1);
						add_char(gote_work,length+1,gote_loc,add[k]);
						result = calc_EXP(gote_work,0,length+1);
						if(result == HUGE_NUM)continue;

						tmp_ans = min(tmp_ans,result); //★★後手は結果を最小化しようとする★★
					}
				}

				//後手が1文字削る
				for(int gote_loc = 0; gote_loc <= length; gote_loc++){
					copy_line(gote_work,work,length+1);
					del_char(gote_work,length+1,gote_loc);
					result = calc_EXP(gote_work,0,length-1);
					if(result == HUGE_NUM)continue;

					tmp_ans = min(tmp_ans,result);
				}

				if(tmp_ans != HUGE_NUM){
					ans = max(ans,tmp_ans); //最小値の最大値
				}
			}
		}

		//先手が1文字削る
		for(int loc = 0; loc <= length-1; loc++){
			copy_line(work,buf,length);
			del_char(work,length,loc);
			tmp = calc_EXP(work,0,length-2);
			if(tmp == HUGE_NUM)continue;

			tmp_ans = HUGE_NUM;

			//後手が1文字加える
			for(int gote_loc = 0; gote_loc <= length-1; gote_loc++){
				for(int k = 0; k < SIZE; k++){
					copy_line(gote_work,work,length-1);
					add_char(gote_work,length-1,gote_loc,add[k]);
					result = calc_EXP(gote_work,0,length-1);
					if(result == HUGE_NUM)continue;

					tmp_ans = min(tmp_ans,result); //★★後手は結果を最小化しようとする★★
				}
			}

			//後手が1文字削る
			for(int gote_loc = 0; gote_loc <= length-2; gote_loc++){
				copy_line(gote_work,work,length-1);
				del_char(gote_work,length-1,gote_loc);
				result = calc_EXP(gote_work,0,length-3);
				if(result == HUGE_NUM)continue;

				tmp_ans = min(tmp_ans,result);
			}

			if(tmp_ans != HUGE_NUM){
				ans = max(ans,tmp_ans); //最小値の最大値
			}
		}
	}

	printf("%lld\n",ans);
}

int main(){


	char buf[NUM];

	while(true){
		scanf("%d %s",&N,buf);
		if(N == 0 && buf[0] == '#')break;

		func(buf);
	}

	return 0;
}



Measured memory_bytes: 3232