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