#include <bits/stdc++.h>
using namespace std;
const int dx[9] = {0, 1, -1, 0, 0, -1, -1, 1, 1};
const int dy[9] = {0, 0, 0, -1, 1, -1, 1, -1, 1};
const double pi = acos(-1.0);
const int N = 110;
int zero[7] = {-1, 1, 2, 2, 1, 0, 0};
int one[7] = {-1, 0, 0, 1, 2, 2, 1};
int two[7] = {-1, 2, 1, 0, 0, 1, 2};
long long n;
int x;
int main() {
  scanf("%lld", &n);
  scanf("%d", &x);
  long long temp = n % 6;
  if (temp == 0) temp = 6;
  if (zero[temp] == x) {
    puts("0");
    return 0;
  }
  if (one[temp] == x) {
    puts("1");
    return 0;
  }
  if (two[temp] == x) {
    puts("2");
    return 0;
  }
  return 0;
}
