#include <bits/stdc++.h>
using namespace std;
int main() {
  int ci, wei;
  int p;
  int a[10] = {2, 2, 1, 0, 0, 1};
  while (cin >> ci >> wei) {
    if (ci % 2 == 1 && wei == 2)
      p = 0;
    else if (ci % 2 == 0 && wei == 2)
      p = 1;
    else if (ci % 2 == 1 && wei == 1)
      p = 2;
    else if (ci % 2 == 0 && wei == 0)
      p = 3;
    else if (ci % 2 == 1 && wei == 0)
      p = 4;
    else if (ci % 2 == 0 && wei == 1)
      p = 5;
    p = (p + ci) % 6;
    cout << a[p] << endl;
  }
  return 0;
}
