#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
int n,x; //规律可以形成一个循环,形成一个环图
string s= "012";
cin >> n >> x;
n %= 6;
for(int i = 1 ; i <= n ; i ++){ //对6取模,然后判断经过剩余的几次后,小球的位置
if(i % 2 == 1) swap(s[0],s[1]);
else swap(s[1] , s[2]); //swap()交换两个位置的元素
}
cout << s[x] << endl;
return 0;
}
/*012 0
102 5
120 4
210 3
201 2
021 1
012 0
从下往上,进行复位*/