#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  scanf("%d %d", &n, &x);
  if (x == 0) {
    if (n & 1) {
      n += 2;
      x = 1;
    } else {
      n++;
      x = 1;
    }
  } else if (x == 2) {
    if (n & 1) {
      n++;
      x = 1;
    } else {
      n += 2;
      x = 1;
    }
  }
  int ara0[] = {-1, 1, 2, 2, 1, 0, 0};
  int ara1[] = {-1, 0, 0, 1, 2, 2, 1};
  int ara2[] = {-1, 2, 1, 0, 0, 1, 2};
  n = n % 6;
  if (n == 0) n = 6;
  if (ara0[n] == x)
    cout << 0 << endl;
  else if (ara1[n] == x)
    cout << 1 << endl;
  else
    cout << 2 << endl;
}
