Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball.

Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.).

Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly n movements were made by the operator and the ball was under shell x at the end. Now he wonders, what was the initial position of the ball?

Input

The first line of the input contains an integer n (1 ≤ n ≤ 2·109) — the number of movements made by the operator.

The second line contains a single integer x (0 ≤ x ≤ 2) — the index of the shell where the ball was found after n movements.

Output

Print one integer from 0 to 2 — the index of the shell where the ball was initially placed.

Examples

Input

4
2


Output

1


Input

1
1


Output

0

Note

In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.

  1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell. 
  2. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell. 
  3. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle. 
  4. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell. 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.StringTokenizer;
import java.util.stream.Collectors;

public class Main {

    FastScanner scanner = new FastScanner();

    private void calc() {
        int n = scanner.nextInt();
        int p = scanner.nextInt();
        int n0 = n % 6;
        int x[][] = new int[3][6];
        x[0] = new int[] {0,1,2,2,1,0};
        x[1] = new int[] {1,0,0,1,2,2};
        x[2] = new int[] {2,2,1,0,0,1};
        
        for (int i = 0; i < 3; i++) {
            if (x[i][n0] == p) {
                System.out.println(i);
                break;
            }
        }
    }

    /*
     * Main Method
     */
    public static void main(String[] args) throws Exception {
        //long s = System.currentTimeMillis();
        new Main().calc();
        // long e = System.currentTimeMillis();
        // System.out.println("Total: " + (e - s) + "ms");
    }
    
    boolean[] fillSieve(int n) {
        boolean[] primes=new boolean[n+1];
        Arrays.fill(primes,true);
        primes[0]=primes[1]=false;
        for (int i=2;i<primes.length;i++) {
            if(primes[i]) {
                for (int j=2;i*j<primes.length;j++) {
                    primes[i*j]=false;
                }
            }
        }
        return primes;
    }

    /*
     * Read input
     */
    int[] rarr(int count) {
        int[] value = new int[count];
        for (int i = 0; i < count; i++) {
            value[i] = scanner.nextInt();
        }
        return value;
    }

    private static final Charset ANSII = Charset.forName("ASCII");

    int[] rstr() {
        String str = scanner.next().trim();
        ByteBuffer buf = ANSII.encode(str);
        byte[] barr = buf.array();
        int[] result = new int[barr.length];
        for (int i = 0; i < barr.length; i++) {
            result[i] = barr[i];
        }
        return result;
    }

    /*
     * Print Methods
     */
    void sout(int n) {
        sout(Integer.valueOf(n));
    }

    void sout(Collection<?> col) {
        for (Object object : col) {
            sout(object);
        }
    }

    void sout(int[] arr) {
        sout(Arrays.stream(arr).mapToObj(i -> "" + i).collect(Collectors.joining(" ")));
    }

    void sout(Object obj) {
        System.out.println(Objects.toString(obj, ""));
    }

    String toString(int[] arr) {
        byte[] buf = new byte[arr.length];
        for (int i = 0; i < arr.length; i++) {
            buf[i] = (byte) arr[i];
        }
        CharBuffer charBuffer = ANSII.decode(ByteBuffer.wrap(buf));
        return new String(charBuffer.array());
    }

    void soutAsString(int[] arr) {
        sout(toString(arr));
    }

    /*
     * Algorithms
     */
    void sort(int[] data) {
        Arrays.sort(data);
    }

    int max(int[] data) {
        return Arrays.stream(data).max().orElse(Integer.MIN_VALUE);
    }

    int min(int[] data) {
        return Arrays.stream(data).min().orElse(Integer.MIN_VALUE);
    }

    int maxIndex(int[] data) {
        int index = 0;
        int m = data[0];
        for (int i = 1; i < data.length; i++) {
            if (m < data[i]) {
                m = data[i];
                index = i;
            }
        }
        return index;
    }

    int power(int a, int b) {
        int res = 1;
        int tmp = a;
        while (b > 0) {
            if ((b & 1) == 1) {
                res *= tmp;
            }
            tmp *= tmp;
            b = b >> 1;
        }
        return res;
    }

    int power(int a, long b, int m) {
        int res = 1;
        int tmp = a;
        while (b > 0) {
            if ((b & 1) == 1) {
                res *= tmp;
                res %= m;
            }
            tmp *= tmp;
            tmp %= m;
            b = b >> 1;
        }
        return res;
    }

    int[] fperiod(int m) {
        int matches = 0;
        List<Integer> f = new ArrayList<>();
        f.add(0);
        f.add(1);
        while (true) {
            int n = f.size();
            if (n % 2 == 0 && matches == n / 2) {
                int[] ans = new int[n / 2];
                for (int i = 0; i < ans.length; i++) {
                    ans[i] = f.get(i);
                }
                return ans;
            }
            int c = (f.get(n - 1) + f.get(n - 2)) % m;
            f.add(c);
            if (f.get(matches).equals(c)) {
                matches++;
            } else {
                matches = (f.get(0).equals(c)) ? 1 : 0;
            }
        }
    }

    int[] factorize(int a) {
        // Шаг 1. Начальная установка. Присвоить t=0,k=0,n=N 
        //        (В ходе выполнения алгоритма переменные t,k,n подчинены следующим условиям: 
        //        n=N/p_{1}...p_{t} и n не имеет простых множителей, меньших d_{k}
        List<Integer> p = new ArrayList<>();
        int n = a;
        int d = 2;

        // Шаг 2. Если n=1, алгоритм заканчивается.
        while (n > 1) {
            // Шаг 3. Разделить. Присвоить q=\lfloor n/d_{k}\rfloor ,r=n\mod d_{k}.
            //        (Здесь q  и r соответственно частное и остаток от деления числа n на d_{k}.)
            int q = n / d;
            int r = n % d;

            // Шаг 4. Остаток равен нулю? Если r neq 0, то перейти к шагу 6.
            if (r == 0) {
                // Шаг 5. Множитель найден. Увеличить t на 1 и присвоить p_{t}=d_{k},n=q. 
                //        Возвратиться к шагу 2.
                p.add(d);
                n = q;
            } else {
                // Шаг 6. Частное мало? Если q>d_{k}, увеличить k на 1 и возвратиться к шагу 3.
                if (q > d) {
                    d += ((d & 1) == 0) ? 1 : 2;
                } else {
                    // Шаг 7. n — простое число. Увеличить t на 1, присвоить p_{t}=n 
                    //        и завершить выполнение алгоритма.
                    p.add(n);
                    break;
                }
            }
        }
        return toArray(p);
    }

    int[] toArray(List<Integer> lst) {
        int[] ans = new int[lst.size()];
        for (int i = 0; i < ans.length; i++) {
            ans[i] = lst.get(i);
        }
        return ans;
    }

    class Euclid {
        final int x, y, d;

        public Euclid(int x, int y, int d) {
            this.x = x;
            this.y = y;
            this.d = d;
        }

        @Override
        public String toString() {
            return "Euclid [x=" + x + ", y=" + y + ", d=" + d + "]";
        }
    }

    Euclid extendedEuclid(int a, int b) {
        int x, y;
        int q, r, x1, x2, y1, y2;

        if (b == 0) {
            return new Euclid(1, 0, a);
        }

        x2 = 1;
        x1 = 0;
        y2 = 0;
        y1 = 1;

        while (b > 0) {
            q = a / b;
            r = a - q * b;
            x = x2 - q * x1;
            y = y2 - q * y1;
            a = b;
            b = r;
            x2 = x1;
            x1 = x;
            y2 = y1;
            y1 = y;
        }

        return new Euclid(x2, y2, a);
    }
}

class FastScanner {
    BufferedReader br;
    StringTokenizer st;

    FastScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }
}