#include <bits/stdc++.h>
using namespace std;
int aa[15], a[15], bb[15];
void work(int dep, int r, int &xx, int &yy, int fx, int fy) {
  if (r == 0) return;
  if (r && r % a[dep - 1] == 0) {
    int x = r / a[dep - 1];
    if (x == 1) yy += aa[dep - 1] * fy;
    if (x == 2) xx += aa[dep - 1] * fx, yy += aa[dep - 1] * fy;
    if (x == 3) xx += (2 * aa[dep - 1] - 1) * fx, yy += (aa[dep - 1] - 1) * fy;
    return;
  }
  if (r < a[dep - 1]) {
    work(dep - 1, r, yy, xx, fy, fx);
    return;
  }
  if (r > 3 * a[dep - 1]) {
    xx += (2 * aa[dep - 1] - 1) * fx;
    yy += (aa[dep - 1] - 1) * fy;
    work(dep - 1, r % a[dep - 1], yy, xx, -fy, -fx);
    return;
  }
  if (r > 2 * a[dep - 1]) xx += aa[dep - 1] * fx;
  yy += aa[dep - 1] * fy;
  work(dep - 1, r % a[dep - 1], xx, yy, fx, fy);
}
int main() {
  int A, B;
  cin >> A >> B;
  aa[0] = a[0] = 1;
  for (int i = 1; i <= A; i++)
    aa[i] = aa[i - 1] * 2, a[i] = a[i - 1] * 4, bb[i] = a[i] - 1;
  int xx = 0, yy = 0;
  work(A, B, xx, yy, 1, 1);
  cout << xx << ' ' << yy << endl;
  return 0;
}
