#include <bits/stdc++.h>
using namespace std;
namespace Stand_IO_Operation {
inline int read() {
  int f = 1, res = 0, ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') res = res * 10 + ch - 48, ch = getchar();
  return f * res;
}
int _sta[1 << 8];
inline void write(int val) {
  if (!val) {
    putchar('0');
    return;
  }
  if (val < 0) putchar('-'), val = -val;
  *_sta = 0;
  while (val > 0) _sta[++*_sta] = val % 10, val /= 10;
  for (int i = *_sta, _Lim = 1; i >= _Lim; i--) putchar(_sta[i] + 48);
}
};  // namespace Stand_IO_Operation
using namespace Stand_IO_Operation;
int n, A[4];
int main() {
  int n = read() % 6;
  A[read()] = true;
  for (int i = n, _Lim = 1; i >= _Lim; i--) {
    if (i % 2)
      swap(A[0], A[1]);
    else
      swap(A[1], A[2]);
  }
  for (int i = 0, _Lim = 2; i <= _Lim; i++)
    if (A[i]) printf("%d\n", i);
}
