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.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.*;

/**
 * Created by Firеfly on 1/1/2017.
 */
public class Task {
    public static void main(String[] args) throws IOException {
        Emaxx emaxx = new Emaxx();
    }
}


class Emaxx {
    static char[] checker;
    FScanner fs;
    PrintWriter pw;
    long MOD = 1000000007;
    HashMap<Integer, Integer> map[];
    int[] mmas;
    int n, m;
    long[][] desk;
    long sum;
    boolean used[];
    ArrayList<Integer> list;
    HashMap<Integer, Integer>[] answer;
    int max;
    int[] hi;
    int[] sums;
    int par;
    int[] parent;
    int[] temp;
    ArrayList<BigInteger> PIQ;
    Emaxx() throws IOException {
        fs = new FScanner(new InputStreamReader(System.in));
        // pw = new PrintWriter(new FileWriter("arithnumbers.out"));
        //  fs = new FScanner(new FileReader("C:\\Users\\Firеfly\\Desktop\\New Text Document.txt"));
        //     fs = new FScanner(new FileReader("input.txt"));;
        //       pw = new PrintWriter("output.txt");
        pw = new PrintWriter(System.out); //PABOTAI, BITARD
        int n = fs.nextInt(), x = fs.nextInt();
        n = n%6;
       if (x == 0) {
            if (n == 0 || n == 5)
                System.out.println(0);
            else if (n == 1 || n == 2)
                System.out.println(1);
            else if (n == 3 || n == 4)
                System.out.println(2);
        } else if (x == 1) {
            if (n == 1 || n == 4)
                System.out.println(0);
            else if (n == 0 || n == 3)
                System.out.println(1);
            else System.out.println(2);
        } else {
            if (n == 2 || n == 3)
                System.out.println(0);
            else if (n == 4 || n == 5)
                System.out.println(1);
            else System.out.println(2);
        }
        pw.close();
    }

    long recursi(ArrayList<Integer>[] mas, int num, int k, HashSet<Integer> set, HashMap<Integer, Integer> nums, long n, long cur) {
        if (k == 1) {
            if (cur * list.get(num) <= n)
                return 1;
            else return 0;
        }
        else {
            long sum = 0;
            for (int i = 0; i<mas[num].size(); i++)
                if (set.contains(mas[num].get(i))) {
                    if (cur*list.get(num)<=n)sum += recursi(mas, nums.get(mas[num].get(i)), k - 1, set, nums, n, cur*list.get(num));
                }
            return sum;
        }
    }

    int make(int[][] orig, int[] combs) {
        for (int i = 3; i<10; i++) {
            for (int j = 0; j<3; j++) {
                int curp = 0;
                int f = 0;
                int s = 1;
                int th = 2;
                if (combs[0] == 1)
                    f+=j;
                if (combs[2] == 1)
                    s+=j;
                if (combs[4] == 1)
                    th+=j;
                int f1 = 0;
                int s1 = 0;
                int th1 = 0;
                if (combs[1] == 1)
                    f1 = i-3;
                if (combs[3] == 1)
                    s1 = i-3;
                if (combs[5] == 1)
                    th1 = i-3;
                orig[i][j] = orig[f1][f] + orig[s1][s] + orig[th1][th];
            }
        }
        return orig[9][2];
    }
    int inv(Pair mas[]) {
        int ans = 0;
        for (int i = 1; i<n; i++) {
            System.out.println(mas[i].x + " " + mas[i].y);
            for (int j = i-1; j>=0; j--) {
                if (mas[j].y>mas[i].y)
                    ans++;
            }
        }
        return ans;
    }


    double len(double x1, double x2, double y1, double y2) {
        return Math.sqrt((x2-x1)*(x2-x1)+(y1-y2)*(y1-y2));
    }

    int find(int cub, int prev) {
        if (cub == 0)
            return 1;
        int ans = 0;
        for (int i = prev+1; i<=cub; i++) {
            ans+=find(cub-i, i);
        }
        return ans;
    }
    int findNum(char[] mas) {
        int size = 1;
        int i  =0 , j = 0;
        for (i = 1,j = mas.length-1; i<=j; i++, j--)
            if ((mas[i]>='0' && mas[i]<='9') || (mas[j]>='0' && mas[j] <='9'))
                break;
            else size++;
        if (i>j)
            return -1;
        else
            return size;
    }

    int findsymb(char[] mas) {
        int size = 1;
        int i = 0, j = 0;
        for (i = 1,j = mas.length-1; i<=j; i++, j--)
            if ((mas[i]>='a' && mas[i]<='z') || (mas[j]>='a' && mas[j] <='z'))
                break;
            else size++;
        if (i>j)return -1;
        else
            return size;
    }

    int findlitts(char[] mas) {
        int size = 1;
        int i= 0, j = 0;
        for (i = 1,j = mas.length-1; i<=j; i++, j--)
            if (mas[i]=='&' || mas[i]=='*' || mas[i] == '#' || mas[j]=='*' || mas[j] =='#' || mas[j] == '&')
                break;
            else size++;
        if (i>j)
            return -1;
        else
            return size;
    }

    boolean ans(int[] second, int first[], int start) {
        int fir = 0;
        int sec = start;
        while (sec<n && first[0] != second[sec])
            sec++;
        int p = sec;
        if (sec == n) {
            return false;}
        else {
            while (sec<n && first[fir] == second[sec])
            {
                sec++;
                fir++;
            }
            if (sec!=n) {
                return false;
            }
            else {
                sec = 0;
                while (sec < p && second[sec] == first[fir]) {
                    sec++;
                    fir++;
                }
                if (sec != p)
                    return false;
                else
                    return true;
            }
        }
    }




    int gcd (int a, int b) {
        if (b == 0)
            return a;
        else
            return gcd(b, a % b);
    }



    /*

        int l1 = le[le.length-1]-46;
        int l2 = le[le.length-2]-46;
        if (l1>=l2)
            l1-=l2;
        else l1 = l1+10-l2;
        System.out.println(l1);
        long ll = dp[le.length][l1];
        int r1 = re[re.length-1]-46;
        int r2 = re[re.length-2]-46;
        if (r1>=r2)
            r1 -=r2;
        else r1 = r1+10-r2;
        long rr = dp[re.length][r1];
     */
    void PP(int[] mas) {
        System.out.println("WAT");
        ArrayList<Character> list = new ArrayList<>();
        for (int i = 0; i<mas.length; i++) {
            System.out.println(mas[i]);
            while (mas[i] > 0) {
                list.add((char) (i + 48));
                mas[i]--;
            }
        }
        Collections.sort(list);
        for (int i = list.size()-1; i>=0; i--)
            pw.print(list.get(i));
    }

    boolean good(int i, int j) {
        if ((i>=0) && (i<n) && (j>=0) && (j<m))
            return true;
        else return false;
    }

    long solve(int i, int j) {
        if (good(i, j))
        {
            if (desk[i][j]==0)
                desk[i][j] += solve(i-1, j-2)+solve(i-2, j-1)+solve(i+1, j-2)+solve(i-2, j+1);
        } else return 0;
        return desk[i][j];
    }
    boolean check(char c) {
        for (int i = 0;i<checker.length; i++)
            if (c == checker[i])
                return true;
        return false;
    }
    void make_set (int v) {
        parent[v] = v;
    }

    int find_set (int v) {
        if (v == parent[v])
            return v;
        return find_set (parent[v]);
    }

    void union_sets (int a, int b) {
        a = find_set (a);
        b = find_set (b);
        if (a != b)
            parent[b] = a;
    }

    static class IntegerUtils {
        public static long[] generateFactorials(int limit, long MOD) {
            long[] result = new long[limit];
            result[0] = 1;
            if (limit == 0) return result;
            for (int i = 1; i < limit; ++i) {
                result[i] = (result[i - 1] * i) % MOD;
            }
            return result;
        }
    }

    int[] Z_function(char[] arr) { //начинается как в начале и идёт как в начале
        int n = arr.length;
        int[] z = new int[n];
        z[0] = 0;
        for (int i = 1, l = 0, r = 0; i<n; i++) {
            if (i<=r)
                z[i] = Math.min(r-i+1, z[i-l]);
            while (i+z[i]<n && arr[i+z[i]] == arr[z[i]])
                z[i]++;
            if (i+z[i]-1>r)
            {
                l = i;
                r = i+z[i]-1;
            }
        }
        return z;
    }

    int[] prefix_function(char[] arr) { // оканчивается на этот символ
        int n = arr.length;
        int[] z = new int[n];
        for (int i = 1; i<n; i++) {
            int j = z[i-1];
            while (j>0 && arr[i] != arr[j]) {
                j=z[j-1];
            }
            if (arr[i] == arr[j]) j++;
            z[i] = j;
        }
        return z;
    }

    long substrings_string(char[] arr) {
        int p = 31;
        int n = arr.length;
        long[] pows = new long[n];
        pows[0] = 1;
        for (int i = 1; i<n; i++)
            pows[i] = pows[i-1]*p;
        long[] prefixes = new long[n];
        for (int i = 0; i<n; i++) {
            prefixes[i] = (arr[i]-'a'+1)*pows[i];
            if (i!=0) prefixes[i]+=prefixes[i-1];
        }

        long res = 0;
        for (int l = 1; l<=n; l++) {
            HashSet<Long> hh = new HashSet<>();
            for (int i = 0; i<n-l+1; i++) {
                long cur_hash = prefixes[i+l-1];
                if (i!=0) cur_hash-=prefixes[i-1];
                cur_hash *= pows[n-i-1];
                hh.add(cur_hash);
            }
            res+=hh.size();
        }
        return res;
    }

    void rabin_Karp(char[] t, char[] s) {
        int p = 31;
        long[] p_pow = new long[Math.max(t.length, s.length)];
        p_pow[0] = 1;
        for (int i = 1; i<p_pow.length; i++)
            p_pow[i] = p_pow[i-1]*p;
        long main_hash = 0;
        for (int i = 0; i<s.length; i++)
            main_hash+=(s[i]-'a'+1)*p_pow[i];
        long hashes[] = new long[t.length];
        for (int i = 0; i<t.length; i++) {
            hashes[i] = (t[i]-'a'+1)*p_pow[i];
            if (i!=0) hashes[i]+=hashes[i-1];
        }
        for (int i = 0; i+s.length-1<t.length; i++) {
            long cur_h = hashes[i+s.length-1];
            if (i!=0) cur_h-=hashes[i-1];
            if (cur_h*p_pow[i] == main_hash)
                System.out.println(i);
        }
    }

    int[] podpalindroms(ArrayList<Character> s) {
        int n = s.size();
        int[] d1 = new int[n]; //odd
        int l = 0;
        int r = -1;
        for(int i = 0; i < n; i++) {
            int k;
            if (i > r) k = 1;
            else k = Math.min(d1[l + r - i], r - i);

            while (0 <= i - k && i + k < n && s.get(i - k) == s.get(i + k)) k++;
            d1[i] = k;
            if (i + k - 1 > r) {
                r = i + k - 1;
                l = i - k + 1;
            }
        }
        int[] res = new int[n];
        for (int i = 0; i<n; i++) {
            System.out.print(d1[i] + " ");
            res[i] = d1[i];
        }
        System.out.println();
        return res;
    }



}

class FScanner {
    BufferedReader br;
    StringTokenizer st;
    FScanner(InputStreamReader isr) {
        br = new BufferedReader(isr);
    }

    FScanner(FileReader fr) {
        br = new BufferedReader(fr);
    }

    String nextToken() throws IOException{
        while (st == null || !st.hasMoreTokens()) {
            String s = br.readLine();
            if (s == null)
                return null;
            st = new StringTokenizer(s);
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextLine() throws IOException {
        return br.readLine();
    }

    char nextChar() throws IOException {
        return (char) br.read();
    }

}

class Gangsta  {
    int t, s, p;
    void setT(int t1) {
        t = t1;
    }
    void setS(int s1) {
        s = s1;
    }
    void setP(int p1) {
        p = p1;
    }


}

class Pair implements Comparable<Pair> {
    int y, x;
    Pair(int x1, int y1) {
        x = x1;
        y = y1;
    }
    @Override
    public int compareTo(Pair o) {
        return -Integer.compare(x, o.x);
    }
}