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