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