#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, x;
  cin >> n >> x;
  n = n % 6;
  for (int i = n; i >= 1; i--) {
    if (i % 2 == 0) {
      if (x == 0) continue;
      if (x == 1)
        x++;
      else
        x--;
      continue;
    }
    if (x == 0)
      x++;
    else if (x == 1)
      x--;
  }
  cout << x << '\n';
}
