#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  cin >> n >> x;
  if (((n - 1) % 6) == (x + 1) || ((n - 1) % 6) == (6 - x) ||
      ((n - 1) % 6 == 0 && x == 0))
    cout << 1 << endl;
  int x0 = (n - 2) % 6;
  if ((n == 1 && x == 1) || x0 == (3 - x) || (x0 == 0 && x == 2) ||
      x0 == (x + 4))
    cout << 0 << endl;
  int x2 = n % 6;
  if (x2 == (3 - x) || x2 == (x + 4) || (x2 == 0 && x == 2)) cout << 2 << endl;
  return 0;
}
