#include <bits/stdc++.h>
using namespace std;
int m, n;
int main() {
  scanf("%d%d", &n, &m);
  n %= 6;
  while (n) {
    if (n == 5) {
      if (m == 0)
        m = 1;
      else if (m == 1)
        m = 0;
    }
    if (n == 4) {
      if (m == 1)
        m = 2;
      else if (m == 2)
        m = 1;
    } else if (n == 3) {
      if (m == 1)
        m = 0;
      else if (m == 0)
        m = 1;
    } else if (n == 2) {
      if (m == 1)
        m = 2;
      else if (m == 2)
        m = 1;
    }
    if (n == 1) {
      if (m == 1)
        m = 0;
      else if (m == 0)
        m = 1;
    }
    n--;
  }
  cout << m << endl;
  return 0;
}
