#include <bits/stdc++.h>
using namespace std;
void sc(char& c) {
  char temp[4];
  scanf("%s", temp);
  c = temp[0];
}
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
int testnum;
int a, b;
int lens[11];
void preprocess() {
  lens[1] = 3;
  for (int i = 2; i <= 10; i++) lens[i] = 4 * lens[i - 1] + 3;
}
pair<int, int> recurse(int a, int b) {
  if (a == 1) {
    if (b == 0) return make_pair(0, 0);
    if (b == 1) return make_pair(0, 1);
    if (b == 2) return make_pair(1, 1);
    if (b == 3) return make_pair(1, 0);
  }
  int z = lens[a - 1];
  if (b <= z) {
    pair<int, int> ret = recurse(a - 1, b);
    return make_pair(ret.second, ret.first);
  }
  b -= z + 1;
  if (b <= z) {
    pair<int, int> ret = recurse(a - 1, b);
    return make_pair(ret.first, ret.second + (1 << (a - 1)));
  }
  b -= z + 1;
  if (b <= z) {
    pair<int, int> ret = recurse(a - 1, b);
    return make_pair(ret.first + (1 << (a - 1)), ret.second + (1 << (a - 1)));
  }
  b -= z + 1;
  if (b <= z) {
    pair<int, int> ret = recurse(a - 1, b);
    return make_pair((1 << a) - 1 - ret.second, (1 << (a - 1)) - 1 - ret.first);
  }
}
void solve() {
  pair<int, int> ret = recurse(a, b);
  printf("%d %d\n", ret.first, ret.second);
}
bool input() {
  scanf("%d", &a);
  scanf("%d", &b);
  return true;
}
int main() {
  preprocess();
  int T = 1;
  for (testnum = 1; testnum <= T; testnum++) {
    if (!input()) break;
    solve();
  }
}
