#include <bits/stdc++.h>
int main() {
  register int x(0), y(0), v(0), r(0), n, d;
  scanf("%u %u", &n, &d);
  for (register int i((n << 1) - 2); i >= 0; i -= 2) {
    r = (v << 2) | (d >> i) & 3;
    x = (x << 1) | (0x936c >> r) & 1;
    y = (y << 1) | (0x39c6 >> r) & 1;
    v = (0x3e6b94c1 >> (r << 1)) & 3;
  }
  printf("%u %u", x, y);
}
