#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, x,
      a[18] = {1, 0, 2, 1, 2, 0, 2, 1, 0, 2, 0, 1, 0, 2, 1, 0, 1, 2};
  cin >> n >> x;
  if ((n - 1) % 6 == 0) {
    if (x == 0)
      cout << a[0] << endl;
    else if (x == 1)
      cout << a[1] << endl;
    else
      cout << a[2] << endl;
  } else if ((n - 2) % 6 == 0) {
    if (x == 0)
      cout << a[3] << endl;
    else if (x == 1)
      cout << a[4] << endl;
    else
      cout << a[5] << endl;
  } else if ((n - 3) % 6 == 0) {
    if (x == 0)
      cout << a[6] << endl;
    else if (x == 1)
      cout << a[7] << endl;
    else
      cout << a[8] << endl;
  } else if ((n - 4) % 6 == 0) {
    if (x == 0)
      cout << a[9] << endl;
    else if (x == 1)
      cout << a[10] << endl;
    else
      cout << a[11] << endl;
  } else if ((n - 5) % 6 == 0) {
    if (x == 0)
      cout << a[12] << endl;
    else if (x == 1)
      cout << a[13] << endl;
    else
      cout << a[14] << endl;
  } else if ((n - 6) % 6 == 0) {
    if (x == 0)
      cout << a[15] << endl;
    else if (x == 1)
      cout << a[16] << endl;
    else
      cout << a[17] << endl;
  }
  return 0;
}
