#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, x, d, c;
  cin >> n >> x;
  if (n % 2 == 0 || x == 2) {
    c = n / 2;
    {
      d = (x + c) % 3;
      cout << d << endl;
    }
  } else {
    c = n / 2;
    if (x == 1) {
      x = 0;
      d = (x + c) % 3;
      cout << d << endl;
    } else if (x == 0) {
      x = 1;
      d = (x + c) % 3;
      cout << d << endl;
    }
  }
}
