from string import digits
import sys
readline = sys.stdin.readline
write = sys.stdout.write
memo = {}
def parse(S):
    key = "".join(S)
    if key in memo:
        return memo[key]
    S = S + ["$"]
    cur = 0
    ALL = 2**32-1
    neg = 2**31
    def expr2():
        nonlocal cur
        r0 = 0
        op = "+"
        while 1:
            r1 = 1
            while 1:
                if S[cur] == "(":
                    cur += 1 # "("
                    r1 *= expr1()
                    cur += 1 # ")"
                else:
                    v = 0
                    while S[cur] in digits:
                        v = 10*v + int(S[cur])
                        cur += 1 # digits
                    r1 *= v
                if S[cur] != "*":
                    break
                cur += 1 # "*"
            if op == "+":
                r0 += r1
            else:
                r0 -= r1
            if S[cur] not in "+-":
                break
            op = S[cur]
            cur += 1 # "+-"
        return r0
    def expr1():
        nonlocal cur
        r0 = 0
        while 1:
            r1 = 0
            while 1:
                r2 = ALL
                while 1:
                    r2 &= expr2()
                    if r2 & neg:
                        r2 -= neg*2
                    if S[cur] != "&":
                        break
                    cur += 1 # "&"
                r1 ^= r2
                if S[cur] != "^":
                    break
                cur += 1 # "^"
            r0 |= r1
            if S[cur] != "|":
                break
            cur += 1 # "|"
        return r0
    memo[key] = r = expr1()
    assert len(key) == cur
    return r
def solve():
    N, S = readline().strip().split()
    N = int(N)
    S = list(S)
    if N == 0:
        return False
    N = 1 if N % 2 else 2
    memo = [{} for i in range(N+1)]
    A = "123456789"
    B = "0123456789"
    C = "*+-&^|"
    def gen(i, S):
        L = len(S)
        if S[0] in B:
            for v in A:
                yield dfs(i+1, [v] + S)
        for k in range(L):
            if k+1 < L and (S[k] == "(" or S[k] in C) and S[k+1] in B:
                for v in A:
                    yield dfs(i+1, S[:k+1] + [v] + S[k+1:])
            elif S[k] in B:
                if k+1 < L and S[k+1] in B:
                    if S[k+1] == "0":
                        continue
                    for c in C:
                        yield dfs(i+1, S[:k+1] + [c] + S[k+1:])
                for v in B:
                    yield dfs(i+1, S[:k+1] + [v] + S[k+1:])
        for k in range(L):
            if S[k] in C and S[k-1] in B and S[k+1] in B:
                yield dfs(i+1, S[:k] + S[k+1:])
            elif S[k] in B:
                if k-1 >= 0 and S[k-1] in B:
                    yield dfs(i+1, S[:k] + S[k+1:])
                elif (k == 0 or S[k-1] == "(" or S[k-1] in C) and (k+1 < L and S[k+1] in B):
                    if S[k+1] == "0":
                        continue
                    yield dfs(i+1, S[:k] + S[k+1:])
    def dfs(i, S):
        key = "".join(S)
        if key in memo[i]:
            return memo[i][key]
        if i == N:
            memo[i][key] = r = parse(S)
            return r
        if i % 2 == 0:
            memo[i][key] = r = max(gen(i, S))
        else:
            memo[i][key] = r = min(gen(i, S))
        return r
    write("%d\n" % dfs(0, S))
    return True
while solve():
    ...


Measured memory_bytes: 34968