#include <bits/stdc++.h>
struct Node {
  int x, y;
  bool operator<(const Node &a) const { return x < a.x; }
};
int n, x, w[6] = {0, 1, 2, 2, 1, 0};
void read(int &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && (ch != '-')) {
    ch = getchar();
  }
  if (ch == '-') f = -1;
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  if (f < 0) x = -x;
}
void read(int &a, int &b) {
  read(a);
  read(b);
}
int main() {
  read(n);
  read(x);
  if (w[n % 6] == x)
    printf("0");
  else if (w[(n + 4) % 6] == x)
    printf("1");
  else
    printf("2");
  return 0;
}
