#include <bits/stdc++.h>
using namespace std;
long long bigMod(long long b, long long p, long long m) {
  if (!p)
    return 1 % m;
  else if (p & 1)
    return (((b % m) + m) % m * bigMod(b, p - 1, m)) % m;
  else {
    long long ret = bigMod(b, p / 2, m);
    return (ret * ret) % m;
  }
}
long long inline gcd(long long x, long long y) {
  return !y ? (long long)abs(x) : gcd(y, x % y);
}
long long inline lcm(long long a, long long b) {
  return ((long long)abs((a / gcd(a, b)) * b));
}
double inline cartesian_dist(double x1, double y1, double x2, double y2) {
  return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
const double PI = acos(-1.0);
const double EPS = 10E-7;
int main() {
  long long n, k;
  while (2 == scanf("%lld %lld", &n, &k)) {
    int rem = n % 6, arr[4];
    memset(arr, 0, sizeof(arr));
    arr[k] = 1;
    for (int i = rem; i >= 1; i--) {
      if (i % 2 == 1)
        swap(arr[0], arr[1]);
      else
        swap(arr[1], arr[2]);
    }
    for (int i = 0; i < 3; i++)
      if (arr[i]) printf("%d", i);
    printf("\n");
  }
  return 0;
}
