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