#include <bits/stdc++.h>
using namespace std;
pair<int, int> gao(int n, int m) {
  int s = 1 << (n * 2 - 2), l = 1 << (n - 1), x = 0, y = 0;
  if (n > 1) tie(x, y) = gao(n - 1, m % s);
  if (m < s) return {y, x};
  if (m < 2 * s) return {x, y + l};
  if (m < 3 * s) return {x + l, y + l};
  return {2 * l - 1 - y, l - 1 - x};
}
int main() {
  int n, m, x, y;
  scanf("%d%d", &n, &m);
  tie(x, y) = gao(n, m);
  printf("%d %d\n", x, y);
}
