#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  scanf("%d", &n);
  scanf("%d", &x);
  n %= 6;
  int arr[] = {0, 1, 2};
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) {
      swap(arr[0], arr[1]);
    } else {
      swap(arr[1], arr[2]);
    }
  }
  cout << arr[x] << endl;
}
