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