#include <bits/stdc++.h>
using namespace std;
int n, x;
const int a[6][3] = {{0, 1, 2}, {1, 0, 2}, {1, 2, 0},
                     {2, 1, 0}, {2, 0, 1}, {0, 2, 1}};
int main() {
  cin >> n >> x;
  n = n % 6;
  cout << a[n][x];
  return 0;
}
