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