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