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