#include <bits/stdc++.h>
using namespace std;
int main() {
  string a = "102120210201021012";
  int x, y;
  cin >> x >> y;
  int p = (x % 6) * 3;
  if (p == 0) {
    cout << a[15 + y] << endl;
  } else {
    cout << a[p - 1 - (2 - y)] << endl;
  }
}
