#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int t;
  cin >> n >> t;
  int x = n % 6;
  int a[3];
  a[0] = 0, a[1] = 1, a[2] = 2;
  int m = 1;
  while (x > 0) {
    if (x % 2 != 0)
      swap(a[m], a[m - 1]);
    else
      swap(a[m], a[m + 1]);
    x--;
  }
  for (int i = 0; i < 3; i++) {
    if (a[i] == t) {
      cout << i;
      break;
    }
  }
}
