#include <bits/stdc++.h>
using namespace std;
int main(int, char *[]) {
  int x, n;
  cin >> n;
  cin >> x;
  n = n % 6;
  int res;
  switch (x) {
    case 0:
      switch (n) {
        case 1:
        case 2:
          res = 1;
          break;
        case 3:
        case 4:
          res = 2;
          break;
        default:
          res = 0;
          break;
      };
      break;
    case 1:
      switch (n) {
        case 1:
        case 4:
          res = 0;
          break;
        case 0:
        case 3:
          res = 1;
          break;
        default:
          res = 2;
          break;
      };
      break;
    case 2:
      switch (n) {
        case 2:
        case 3:
          res = 0;
          break;
        case 4:
        case 5:
          res = 1;
          break;
        default:
          res = 2;
          break;
      };
      break;
  }
  cout << res;
  return 0;
}
