#include <bits/stdc++.h>
using namespace std;
int m, n;
int a[7] = {5, 11, 15, 21, 19, 7, 5};
int main() {
  scanf("%d%d", &n, &m);
  n %= 6;
  if (m == 0)
    cout << a[n] / 9 << endl;
  else if (m == 1)
    cout << a[n] / 3 % 3 << endl;
  else
    cout << a[n] % 3 << endl;
  return 0;
}
