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