#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> f(long long d, long long k) {
  if (k == 1) {
    if (d == 1) return {1, 1};
    if (d == 2) return {1, 2};
    if (d == 3) return {2, 2};
    if (d == 4) return {2, 1};
  }
  long long cur_d = 1 << (2 * (k - 1));
  if (cur_d >= d) {
    pair<long long, long long> res = f(d, k - 1);
    return {res.second, res.first};
  } else if (2 * cur_d >= d) {
    pair<long long, long long> res = f(d - cur_d, k - 1);
    return {res.first, res.second + (1 << (k - 1))};
  } else if (3 * cur_d >= d) {
    pair<long long, long long> res = f(d - 2 * cur_d, k - 1);
    return {res.first + (1 << (k - 1)), res.second + (1 << (k - 1))};
  } else if (4 * cur_d >= d) {
    pair<long long, long long> res = f(d - 3 * cur_d, k - 1);
    return {(1 << (k)) - res.second + 1, (1 << (k - 1)) - res.first + 1};
  }
}
int main() {
  long long a, b;
  cin >> a >> b;
  b++;
  pair<long long, long long> res = f(b, a);
  cout << res.first - 1 << " " << res.second - 1 << endl;
}
