#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, n, x;
  int a[10] = {2, 3, 3, 2, 1, 1};
  int b[10] = {1, 1, 2, 3, 3, 2};
  int c[10] = {3, 2, 1, 1, 2, 3};
  cin >> n >> x;
  n %= 6;
  if (n == 0) {
    n = 6;
  }
  if (x == a[n - 1] - 1) {
    cout << "0";
  } else if (x == b[n - 1] - 1) {
    cout << "1";
  } else if (x == c[n - 1] - 1) {
    cout << "2";
  }
}
