#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  cin >> n >> x;
  if (x == 0) {
    if ((n % 6 == 0) || (n % 6 == 5)) cout << 0;
    if ((n % 6 == 1) || (n % 6 == 2)) cout << 1;
    if ((n % 6 == 3) || (n % 6 == 4)) cout << 2;
  }
  if (x == 1) {
    if ((n % 6 == 1) || (n % 6 == 4)) cout << 0;
    if ((n % 6 == 0) || (n % 6 == 3)) cout << 1;
    if ((n % 6 == 2) || (n % 6 == 5)) cout << 2;
  }
  if (x == 2) {
    if ((n % 6 == 2) || (n % 6 == 3)) cout << 0;
    if ((n % 6 == 4) || (n % 6 == 5)) cout << 1;
    if ((n % 6 == 0) || (n % 6 == 1)) cout << 2;
  }
}
