#include <bits/stdc++.h>
using namespace std;
int solve1(int n) {
  int aux = n / 6;
  n -= aux * 6;
  aux = n;
  if (aux == 0) return 0;
  if (aux == 5) return 0;
  if (aux == 4) return 1;
  if (aux == 3) return 2;
  if (aux == 2) return 2;
  if (aux == 1) return 1;
}
int solve2(int n) {
  int aux = n / 6;
  n -= aux * 6;
  aux = n;
  if (aux == 0) return 1;
  if (aux == 5) return 2;
  if (aux == 4) return 2;
  if (aux == 3) return 1;
  if (aux == 2) return 0;
  if (aux == 1) return 0;
}
int solve3(int n) {
  int aux = n / 6;
  n -= aux * 6;
  aux = n;
  if (aux == 0) return 2;
  if (aux == 5) return 1;
  if (aux == 4) return 0;
  if (aux == 3) return 0;
  if (aux == 2) return 1;
  if (aux == 1) return 2;
}
int main() {
  int n, x;
  cin >> n >> x;
  if (solve1(n) == x)
    cout << "0";
  else if (solve2(n) == x)
    cout << "1";
  else
    cout << "2";
  return 0;
}
