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