#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
static bool constexpr dbg = 0;
ll constexpr NM = -1;
char const* const str = "012102120210201021012";
int main() {
  if (!dbg) {
    std::ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
  ll n, x;
  cin >> n >> x;
  cout << str[n % 6 * 3 + x] << endl;
  return 0;
}
