#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const long long INFF = 1e18;
int main(void) {
  vector<vector<int>> v = {
      {0, 1, 2}, {1, 0, 2}, {1, 2, 0}, {2, 1, 0}, {2, 0, 1}, {0, 2, 1},
  };
  int n, x;
  cin >> n >> x;
  n %= 6;
  printf("%d\n", v[n][x]);
  return 0;
}
