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