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