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.util.*;
import java.util.stream.Collectors;

public class Solution {

    public static void main(String[] args) throws IOException {
        IO io = new IO() ;
        int n = io.getInt(), x = io.getInt() ;
        n = n % 6 ;

        for(int i = 0 ; i < 3 ; i++){
            int ind = starts(i, n) ;
            if(ind == x){
                System.out.println(i) ;
            }
        }
    }
    public static int starts(int s, int n){
        List<Integer> state = new ArrayList<>() ;
        state.add(0) ;
        state.add(0) ;
        state.add(0) ;
        state.set(s, 1) ;
        for(int i = 0 ; i < n ; i++){
            if((i + 1) % 2 != 0)
                Utils.swap(state, 0, 1) ;
            else
                Utils.swap(state, 1, 2) ;
        }
        return state.indexOf(1) ;
    }
}

class Utils {

    static int[][] fourDirs = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}} ;
    static int[][] eightDirs = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}} ;

    public static boolean isPrime(long n){
        long sqrt = (long)Math.sqrt(n) ;
        for(int i = 2 ; i <= sqrt ; i++){
            if(n % i == 0)
                return false ;
        }
        return true ;
    }

    public static long mod(long n){
        if(n > 0)
            return n % 1000000007 ;
        return (n + 2000000014) % 1000000007 ;
    }

    public static boolean isSqr(long n){
        int sqrt = (int) Math.sqrt(n) ;
        return n == (long)sqrt*sqrt ;
    }

    public static Utils.Pair getSlope(int x0, int y0, int x1, int y1){
        int a = y1 - y0, b = x1 - x0, g = (int)Utils.gcd(Math.abs(a), Math.abs(b)) ;
        if(g != 0){
            a /= g ;
            b /= g ;
        }
        if(a < 0){
            a *= -1 ;
            b *= -1 ;
        }
        else if(a == 0){
            b = 1 ;
        }
        return new Utils.Pair(a, b) ;
    }

    public static boolean inRange(long i, long l, long h){
        return i >= l && i <= h ;
    }

    public static boolean isValid(int i, int j, int n, int m){
        return i >= 0 && j >= 0 && i < n && j < m ;
    }

    public static void swap(List<Integer> ls, int i, int j){
        int temp = ls.get(i) ;
        ls.set(i, ls.get(j)) ;
        ls.set(j, temp) ;
    }

    public static long gcd(long a, long b){
        if(a < b)
            return gcd(b, a) ;
        else if(a == b || b == 0)
            return a ;
        else{
            return gcd(b, a % b) ;
        }
    }

    public static long subSum(long[] pre, int l, int h){
        return l == 0 ? pre[h]: pre[h] - pre[l - 1] ;
    }

    public static class Pair implements Comparable<Pair>{
        public int l, h ;

        public Pair(int a, int b) {
            this.l = a;
            this.h = b;
        }

        @Override
        public int compareTo(Pair o) {
            return l - o.l ;
        }

        @Override
        public String toString() {
            return "Pair{" +
                    "l=" + l +
                    ", h=" + h +
                    '}';
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            Pair pair = (Pair) o;

            if (l != pair.l) return false;
            return h == pair.h;
        }

        @Override
        public int hashCode() {
            int result = l;
            result = 31 * result + h;
            return result;
        }
    }

    public static void ifPrint(boolean test, Object ifValue, Object elseValue){
        System.out.println(test ? ifValue: elseValue) ;
    }

    public static void print(Character delim, Object... a){
        List<String> top = new ArrayList<>() ;
        for(Object aa: a)
            top.add(aa == null ? "null": aa.toString()) ;
        System.out.println(join(top, delim.toString())) ;
    }

    public static void print(Object... a){
        print(' ', a) ;
    }

    public static  <T extends Comparable<T>> int lowerBound(T[] arr, int l, int h, T key){
        while(l < h){
            int mid = (l + h) / 2 ;
            if(arr[mid].compareTo(key) < 0)
                l = mid + 1 ;
            else
                h = mid ;
        }
        return arr[l].compareTo(key) >= 0 ? l: -1 ;
    }

    public static <T extends Comparable<T>> int upperBound(T[] arr, int l, int h, T key){
        while(l < h){
            int mid = (l + h) / 2 ;
            if(arr[mid].compareTo(key) < 0)
                l = mid + 1 ;
            else if(arr[mid].compareTo(key) == 0)
                l = mid ;
            else
                h = mid ;
            if(h == l + 1)
                break ;
        }
        return arr[l].compareTo(key) >= 0 ? l: -1 ;
    }

    public static class IndexedElement<T> {
        int idx;
        T val;

        public IndexedElement(int idx, T val) {
            this.idx = idx;
            this.val = val;
        }

        @Override
        public String toString() {
            return "IndexedElement{" +
                    "idx=" + idx +
                    ", val=" + val +
                    '}';
        }
    }

    public static <T> ArrayList<IndexedElement<T>> getIndexedArray(List<T> ip) {
        ArrayList<IndexedElement<T>> op = new ArrayList<>();
        for (int i = 0; i < ip.size(); i++) {
            op.add(new IndexedElement<>(i, ip.get(i)));
        }
        return op;
    }

    public static <T> String join(List<T> ls) {
        return join(ls, " ") ;
    }

    public static <T> String join(List<T> ls, String delim) {
        StringJoiner sj = new StringJoiner(delim);
        for (T a : ls)
            sj.add(a.toString());
        return sj.toString();
    }

    public static <T> void print2DArray(List<List<T>> mat) {
        for (List<T> m : mat) {
            System.out.println("{ " + join(m, ", ") + " }");
        }
    }

    public static  <T> void reverseArrray(T[] arr, int l, int h){
        while(l < h){
            T temp = arr[l] ;
            arr[l] = arr[h] ;
            arr[h] = temp ;
            l++ ;
            h-- ;
        }
    }
}

class IO {
    private BufferedReader br = null;
    private StringTokenizer st = null;

    public IO() {
        this(System.in);
    }

    public IO(InputStream is) {
        this.br = new BufferedReader(new InputStreamReader(is));
    }

    public List<String> getStringArray(int n) throws IOException {
        if (n == 0)
            return new ArrayList<>();
        if (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        List<String> res = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            if (!st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            res.add(st.nextToken());
        }
        return res;
    }
    public String getString() throws IOException {
        List<String> res = this.getStringArray(1);
        return res.size() == 0 ? "" : res.get(0);
    }

    public List<Integer> getIntegerArray(int n) throws IOException {
        if (n == 0)
            return new ArrayList<>();
        List<String> res = getStringArray(n);
        return res.stream().map(Integer::parseInt).collect(Collectors.toList());
    }
    public Integer getInt() throws IOException {
        List<Integer> res = this.getIntegerArray(1);
        return res.size() == 0 ? 0 : res.get(0);
    }

    public List<Long> getLongArray(int n) throws IOException {
        if (n == 0)
            return new ArrayList<>();
        List<String> res = getStringArray(n);
        return res.stream().map(Long::parseLong).collect(Collectors.toList());
    }
    public Long getLong() throws IOException {
        List<Long> res = this.getLongArray(1);
        return res.size() == 0 ? 0L : res.get(0);
    }

    public List<Double> getDoubleArray(int n) throws IOException {
        if (n == 0)
            return new ArrayList<>();
        List<String> res = getStringArray(n);
        return res.stream().map(Double::parseDouble).collect(Collectors.toList());
    }
    public Double getDouble() throws IOException {
        List<Double> res = this.getDoubleArray(1);
        return res.size() == 0 ? 0.0 : res.get(0);
    }
}