#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <complex>
#include <queue>
#include <functional>
#include <sstream>
#include <climits>
#include <map>
using namespace std;

typedef long long LL;

const char *P;

LL aexpr();
LL xexpr();
LL oexpr();
LL expr();
LL term();
LL fact();

LL oexpr(){
	LL x = xexpr();
	while(*P == '|'){
		++P;
		x |= xexpr();
	}
	return x;
}

LL xexpr(){
	LL x = aexpr();
	while(*P == '^'){
		++P;
		x ^= aexpr();
	}
	return x;
}

LL aexpr(){
	LL x = expr();
	while(*P == '&'){
		++P;
		x &= expr();
	}
	return x;
}

LL expr(){
	LL x = term();
	while(1){
		if(*P == '+'){
			++P;
			x += term();
		}
		else if(*P == '-'){
			++P;
			x -= term();
		}
		else{
			break;
		}
	}
	return x;
}

LL term(){
	LL x = fact();
	while(*P == '*'){
		++P;
		x *= fact();
	}
	return x;
}

LL fact(){
	if(*P == '('){
		++P;
		LL x = oexpr();
		if(*P != ')'){
			throw 0;
		}
		++P;
		return x;
	}

	if(*P == '0' || !isdigit(*P)){
		throw "";
	}

	char *endp;
	LL x = strtoll(P, &endp, 10);
	P = endp;
	return x;
}


const string chs = "0123456789*+-&^|";

inline void update(LL &x, LL y, bool fst){
	if(fst){
		x = max(x, y);
	}
	else{
		x = min(x, y);
	}
}


LL solve(int n, const string &s, bool fst){
	LL ret;
	if(fst){
		ret = LLONG_MIN;
	}
	else{
		ret = LLONG_MAX;
	}

	try{
		P = s.c_str();
		LL t = oexpr();
		if(*P){ throw 0; }
		if(!n){
			return t;
		}
	}catch(...){
		if(fst){
			ret = LLONG_MAX;
		}
		else{
			ret = LLONG_MIN;
		}
		return ret;
	}

	for(int i = 0; i < s.size(); ++i){
		if(s[i] == '(' || s[i] == ')'){ continue; }
		string t = s;
		t.erase(t.begin() + i);
		LL x = solve(n - 1, t, !fst);
		update(ret, x, fst);
	}

	for(int i = 0; i <= s.size(); ++i){
		for(int j = 0; j < chs.size(); ++j){
			string t = s;
			t.insert(t.begin() + i, chs[j]);
			LL x = solve(n - 1, t, !fst);
			update(ret, x, fst);
		}
	}
	
	return ret;
}


int main(){
	int n;
	int cnt = 0;
	string s;
	while(cin >> n >> s, n){
		if(n % 2){ n = 1; }
		else{ n = 2; }
		cout << solve(n, s, true) << endl;
	}
}