#include <bits/stdc++.h>
using namespace std;
int printx(int x, int a, int b, int c) {
  if (x == 0)
    return a;
  else if (x == 1)
    return b;
  else
    return c;
}
int main() {
  long long n;
  int x;
  cin >> n >> x;
  n %= 6;
  switch (n) {
    case 0:
      x = printx(x, 0, 1, 2);
      break;
    case 1:
      x = printx(x, 1, 0, 2);
      break;
    case 2:
      x = printx(x, 1, 2, 0);
      break;
    case 3:
      x = printx(x, 2, 1, 0);
      break;
    case 4:
      x = printx(x, 2, 0, 1);
      break;
    case 5:
      x = printx(x, 0, 2, 1);
      break;
  }
  cout << x << endl;
  return 0;
}
