#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int x;
  cin >> n >> x;
  int a[3] = {0, 1, 2};
  a[x] = 3;
  n = n % 30;
  int k = n;
  for (int i = 0; i < n; i++) {
    if (k & 1)
      swap(a[0], a[1]);
    else
      swap(a[1], a[2]);
    k--;
  }
  for (int i = 0; i < 3; i++)
    if (a[i] == 3) cout << i;
  return 0;
}
