$chars = %w(1 2 3 4 5 6 7 8 9 0 + - * & | ^)
$zero_ops = %w(0 + - * & | ^)

def check_valid(e)
	return false if e =~ /\(\)/
	return false if e =~ /\b0\d+\b/
	return false if e =~ /[-+*&|^]{2,}/
	return false if e =~ /(?<![)\d])[-+*&|^]/
	return false if e =~ /[-+*&|^](?![(\d])/
	return false if e =~ /\)(?![-+*&|^)]|$)/
	return false if e =~ /(?<![-+*&|^(]|^)\(/

	return true
end

def max_min(n, e, lb, ub)
	ev = eval(e)	
	return ev if n == 0

	if n.even?
		ub = ev if ev < ub
	else
		return ev = max_min(1, e, lb, ub) if n > 1
		lb = ev if lb < ev
	end

	if e.size > 1
		(0..e.size-1).each do |i|
			next if e[i] == ?( || e[i] == ?)
			s = e.dup
			s.slice!(i)
			next unless check_valid(s)
			mm = min_max(n-1, s, lb, ub)
			lb = mm if mm > lb
			return ub if lb >= ub
		end
	end

	(0..e.size).each do |i|
		l = (i == 0 ? "" : e[0..i-1])
		r = e[i..-1]

		next unless check_valid(l + ?1 + r)
		(1..9).to_a.shuffle.each do |k|
			mm = min_max(n-1, l + k.to_s + r, lb, ub)
			lb = mm if mm > lb
			return ub if lb >= ub
		end

		$zero_ops.shuffle.each do |k|
			s = l + k + r
			break unless check_valid(s)
			mm = min_max(n-1, s, lb, ub)
			lb = mm if mm > lb
			return ub if lb >= ub
		end
	end
	lb
end

def min_max(n, e, lb, ub)
	ev = eval(e)
	return ev if n == 0

	if n.even?
		lb = ev if lb < ev
	else
		return ev = max_min(1, e, lb, ub) if n > 1
		ub = ev if ev < ub
	end

	if e.size > 1
		(0..e.size-1).each do |i|
			next if e[i] == ?( || e[i] == ?)
			s = e.dup
			s.slice!(i)
			next unless check_valid(s)
			mm = max_min(n-1, s, lb, ub)
			ub = mm if mm < ub
			return lb if ub <= lb
		end
	end

	(0..e.size).each do |i|
		l = (i == 0 ? "" : e[0..i-1])
		r = e[i..-1]

		next unless check_valid(l + ?1 + r)
		(1..9).to_a.shuffle.each do |k|
			mm = max_min(n-1, l + k.to_s + r, lb, ub)
			ub = mm if mm < ub
			return lb if ub <= lb
		end

		$zero_ops.shuffle.each do |k|
			s = l + k + r
			break unless check_valid(s)
			mm = max_min(n-1, s, lb, ub)
			ub = mm if mm < ub
			return lb if ub <= lb
		end
	end
	ub
end

loop do
	n, e = gets.split
	n = n.to_i
	break if n == 0
	puts max_min(n, e.chomp, -Float::INFINITY, Float::INFINITY)	
end