Nim Matrix
Function Sprague-Grundy graph (X, F) is a function g: X → N such that
g(x) = min{n ≥ 0 : n ≠ g(y) y F(x)}.
This formula can be written compactly using the concept of mex (minimal excludant). The minimal excludant set of stylish non-negative integers defined as the smallest non-negative number not belonging to this set. Then
g(x) = mex{g(y) : y F(x)}.
Suppose that S can only be non-negative integers. We define the mex(S) as the smallest element of not S. Then the infinite matrix A is defined as: A(0, 0) = 0, A(i, j) = mex(S),where S is found from S = S_1 AND S_2,S_1 = {A(k, j), k < i}, S_2 = {A(i, k), k < i}. Below are a few first values of this matrix:
Your task is to compute the relevant elements of this matrix.
Input
Input data contains a few test cases, each of which is in a separate row contains the row number and column number for which to calculate the value of a matrix. Input does not exceed 2·10^9.
Output
For each test case in a separate row, a corresponding value of the matrix.