#include <bits/stdc++.h>
using namespace std;
int z[6][3] = {{0, 1, 2}, {1, 0, 2}, {1, 2, 0},
               {2, 1, 0}, {2, 0, 1}, {0, 2, 1}};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int i, n, x;
  cin >> n >> x;
  cout << z[n % 6][x] << endl;
}
