from collections import deque

def bit_convert(a):
    temp_list = deque()
    while a:
        temp_list.appendleft(a % 2)
        a //=2
    return temp_list

def anti_bit_convert(input_list):
    temp = 0
    total = 0
    while input_list:
        total += input_list.pop() * 2**temp
        temp+=1
    return total


def bitwise_half_add(a,b):
    bit_a = bit_convert(a)
    bit_b = bit_convert(b)
    n = len(bit_a)
    m = len(bit_b)
    while m > n:
        bit_a.appendleft(0)
        n+=1
    while n > m:
        bit_b.appendleft(0)
        m+=1
    total = deque()
    while bit_a:
        total.appendleft(bit_a.pop() ^ bit_b.pop())
    return anti_bit_convert(total)


def multi_half_add(input_list):
    #here, the idea is going to be to shorten the input list down as much as possible
    while len(input_list) > 1:
        a = input_list.pop()
        b = input_list.pop()
        input_list.append(bitwise_half_add(a,b))
    return input_list[0]

hook_grundy_values = {}

def hook_grundy(a,b):
    #We need to define this into sections, 
    #first, if we already have computed our grundy value, let's just access a dictionary to grab that
    if (a,b) in hook_grundy_values.keys():
        return hook_grundy_values.get((a,b))
    #Now, let's give some exit conditions: if one of the legs is really small, we can just give the grundy value easy
    if a == -1:
        hook_grundy_values[(a,b)] = b
        return b
    if a == 0:
        hook_grundy_values[(a,b)] = b+1
        return b+1
    if b == -1:
        hook_grundy_values[(a,b)] = a
        return a
    if b == 0:
        hook_grundy_values[(a,b)] = a+1
        return a+1
    #okay, the hook is not small, so we need to say what actions can we do on it, and add those grundys to a list
    #we then use sprague-grundy theory to say that the minimum not in this list is the grundy value
    else:
        temp_list = []
        for n in range(1,b+2):
            #our one action:
            for j in range (0,n):
                temp_list.append(bitwise_half_add(hook_grundy(a,b-n), j))
            #and lastly, to take pips from the corner and move out from there, making two lines
        for m in range(1,a+2):
            #and we do the same things here
            for j in range(0,m):
                temp_list.append(bitwise_half_add(hook_grundy(a-m,b), j))
        #so now we need to find the minimum in our temp_list and return that.
        Case = True
        n = 1
        while Case:
            if n not in temp_list:
                value = n
                Case = False
            else: n+=1
        hook_grundy_values[(a,b)] = value
        return value
   
for n in range(0,16):
    for m in range(0,16):
        if m >= n:
            print((m,n), hook_grundy(m,n))