#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, x;
  cin >> n >> x;
  int a[7] = {0, 1, 1, 2, 2, 0};
  int b[7] = {1, 0, 2, 1, 0, 2};
  int c[7] = {2, 2, 0, 0, 1, 1};
  n = n % 6;
  if (x == 0)
    cout << a[n] << endl;
  else if (x == 1)
    cout << b[n] << endl;
  else
    cout << c[n] << endl;
  return 0;
}
