#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const double PI = acos(-1);
const double EPS = 1e-8;
vector<pair<int, int> > v;
void func(int N, int x, int y, int type) {
  if (N == 1) {
    v.push_back(pair<int, int>(x, y));
    return;
  }
  int NN = N / 2;
  int xx = x + N / 2;
  int yy = y + N / 2;
  if (type == 0) {
    func(NN, x, y, 1);
    func(NN, x, yy, 0);
    func(NN, xx, yy, 0);
    func(NN, xx, y, 2);
  } else if (type == 1) {
    func(NN, x, y, 0);
    func(NN, xx, y, 1);
    func(NN, xx, yy, 1);
    func(NN, x, yy, 3);
  } else if (type == 2) {
    func(NN, xx, yy, 3);
    func(NN, x, yy, 2);
    func(NN, x, y, 2);
    func(NN, xx, y, 0);
  } else if (type == 3) {
    func(NN, xx, yy, 2);
    func(NN, xx, y, 3);
    func(NN, x, y, 3);
    func(NN, x, yy, 1);
  }
}
int main() {
  int a, b;
  cin >> a >> b;
  int N = 1 << a;
  func(N, 0, 0, 0);
  cout << v[b].first << " " << v[b].second << endl;
}
