#include <bits/stdc++.h>
using namespace std;
int num[15];
int h[15];
int x[100], y[100];
void calc(int b, int d) {
  if (b == 0) {
    x[d] = y[d] = 0;
    return;
  }
  int i = 10;
  while (num[i] > b) {
    i--;
  }
  int t = b / (num[i]);
  b %= (num[i]);
  calc(b, d + 1);
  if (i % 2 == 1) {
    if (t == 0) {
      x[d] = x[d + 1];
      y[d] = y[d + 1];
    } else if (t == 1) {
      x[d] = y[d + 1];
      y[d] = x[d + 1] + h[i];
    } else if (t == 2) {
      x[d] = y[d + 1] + h[i];
      y[d] = x[d + 1] + h[i];
    } else {
      x[d] = h[i] + h[i] - 1 - x[d + 1];
      y[d] = h[i] - 1 - y[d + 1];
    }
  } else {
    if (t == 0) {
      x[d] = x[d + 1];
      y[d] = y[d + 1];
    } else if (t == 1) {
      x[d] = h[i] + y[d + 1];
      y[d] = x[d + 1];
    } else if (t == 2) {
      x[d] = h[i] + y[d + 1];
      y[d] = h[i] + x[d + 1];
    } else {
      x[d] = h[i] - 1 - x[d + 1];
      y[d] = h[i] + h[i] - 1 - y[d + 1];
    }
  }
}
int main(void) {
  int a, b;
  cin >> a >> b;
  num[0] = 0;
  h[0] = 0;
  for (int i = 1; i <= 10; i++) {
    num[i] = num[i - 1] * 4 + 3;
    num[i - 1]++;
    h[i] = h[i - 1] * 2 + 1;
    h[i - 1]++;
  }
  num[10]++;
  h[10]++;
  calc(b, 0);
  if (a % 2 == 1) {
    swap(x[0], y[0]);
  }
  cout << x[0] << ' ' << y[0] << endl;
  return 0;
}
