#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, x;
  cin >> n >> x;
  n = n % 6;
  ;
  for (int i = n; i > 0; i--) {
    if (i & 1) {
      if (x == 1)
        x = 0;
      else if (x == 0)
        x = 1;
    } else {
      if (x == 2)
        x = 1;
      else if (x == 1)
        x = 2;
    }
  }
  cout << x;
  return 0;
}
