#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
  int t;
  solve();
  return 0;
}
int find(int init, int k, int chance) {
  if (k == 0) return init;
  if (chance % 2 == 0) {
    if (init == 1) {
      return find(2, k - 1, 1);
    } else if (init == 2) {
      return find(1, k - 1, 1);
    } else {
      return find(0, k - 1, 1);
    }
    chance = 1;
  } else {
    if (init == 2) {
      return find(2, k - 1, 0);
    } else if (init == 1) {
      return find(0, k - 1, 0);
    } else {
      return find(1, k - 1, 0);
    }
  }
}
void solve() {
  int n, k;
  cin >> n >> k;
  n %= 6;
  if (find(1, n, 1) == k) {
    cout << 1 << endl;
  } else if (find(2, n, 1) == k) {
    cout << 2 << endl;
  } else {
    cout << 0 << endl;
  }
}
