#include <bits/stdc++.h>
using namespace std;
long long int bigMod(long long int A, long long int P, int M) {
  long long int R = 1;
  for (A %= M; P; P >>= 1) {
    if (P & 1) R = (R * A) % M;
    A = (A * A) % M;
  }
  return R;
}
long long int bigMul(long long int A, long long int B, long long int M) {
  long long int R = 0;
  for (A %= M; B; B >>= 1) {
    if (B & 1) R = (R + A) % M;
    A = (A + A) % M;
  }
  return R;
}
long long int negMod(long long int A, long long int B) {
  return (((A % B) + B) % B);
}
long long int invMod(long long int A, long long int M) {
  return bigMod(A, M - 2, M);
}
unsigned long long int _pow(unsigned long long int A, int P) {
  unsigned long long int R = 1;
  for (; P; P >>= 1) {
    if (P & 1) R = (R * A);
    A = (A * A);
  }
  return R;
}
template <class T>
T GCD(T x, T y) {
  while (x) x ^= y ^= x ^= y %= x;
  return y;
}
template <class T>
T LCM(T x, T y) {
  return (x / GCD(x, y)) * y;
}
int main() {
  long long int n, x;
  cin >> n >> x;
  long long int m = n % 3;
  if (n % 2 == 0) {
    if (m == 0) {
      if (x == 0)
        cout << "0" << endl;
      else if (x == 1)
        cout << "1" << endl;
      else if (x == 2)
        cout << "2" << endl;
      return 0;
    } else if (m == 1) {
      if (x == 0)
        cout << "2" << endl;
      else if (x == 1)
        cout << "0" << endl;
      else if (x == 2)
        cout << "1" << endl;
      return 0;
    } else if (m == 2) {
      if (x == 0)
        cout << "1" << endl;
      else if (x == 1)
        cout << "2" << endl;
      else if (x == 2)
        cout << "0" << endl;
      return 0;
    }
  } else {
    if (m == 0) {
      if (x == 0)
        cout << "2" << endl;
      else if (x == 1)
        cout << "1" << endl;
      else if (x == 2)
        cout << "0" << endl;
      return 0;
    } else if (m == 1) {
      if (x == 0)
        cout << "1" << endl;
      else if (x == 1)
        cout << "0" << endl;
      else if (x == 2)
        cout << "2" << endl;
      return 0;
    } else if (m == 2) {
      if (x == 0)
        cout << "0" << endl;
      else if (x == 1)
        cout << "2" << endl;
      else if (x == 2)
        cout << "1" << endl;
      return 0;
    }
  }
  return 0;
}
