#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2 * 1e5 + 10;
ll a[N];
int main() {
  ll n, x;
  cin >> n >> x;
  n %= 6;
  a[0] = 0, a[1] = 1, a[2] = 2;
  for (int i = 1; i <= n; ++i) {
    if (i & 1)
      swap(a[0], a[1]);
    else
      swap(a[1], a[2]);
  }
  cout << a[x];
}
