#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n1, n, x;
  cin >> n1 >> x;
  n = n1 % 6;
  if (n == 0 && x == 1) {
    cout << 1;
    return 0;
  } else if (n == 1 && x == 0) {
    cout << 1;
    return 0;
  } else if (n == 2 && x == 0) {
    cout << 1;
    return 0;
  } else if (n == 3 && x == 1) {
    cout << 1;
    return 0;
  } else if (n == 4 && x == 2) {
    cout << 1;
    return 0;
  } else if (n == 5 && x == 2) {
    cout << 1;
    return 0;
  }
  if (n == 0 && x == 2) {
    cout << 2;
    return 0;
  } else if (n == 1 && x == 2) {
    cout << 2;
    return 0;
  } else if (n == 2 && x == 1) {
    cout << 2;
    return 0;
  } else if (n == 3 && x == 0) {
    cout << 2;
    return 0;
  } else if (n == 4 && x == 0) {
    cout << 2;
    return 0;
  } else if (n == 5 && x == 1) {
    cout << 2;
    return 0;
  }
  if (n == 0 && x == 0) {
    cout << 0;
    return 0;
  } else if (n == 1 && x == 1) {
    cout << 0;
    return 0;
  } else if (n == 2 && x == 2) {
    cout << 0;
    return 0;
  } else if (n == 3 && x == 2) {
    cout << 0;
    return 0;
  } else if (n == 4 && x == 1) {
    cout << 0;
    return 0;
  } else if (n == 5 && x == 0) {
    cout << 0;
    return 0;
  }
  cout << 1;
}
