#include <bits/stdc++.h>
using namespace std;
inline long long IN() {
  long long x = 0;
  int ch = getchar(), f = 1;
  while (!isdigit(ch) && (ch != '-') && (ch != EOF)) ch = getchar();
  if (ch == '-') {
    f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void OUT(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10)
    OUT(x / 10), putchar(x % 10 + '0');
  else
    putchar(x + '0');
}
pair<int, int> Solve(int Cs, int Nb) {
  if (Cs == 1) {
    if (Nb == 0) return make_pair(0, 0);
    if (Nb == 1) return make_pair(1, 0);
    if (Nb == 2) return make_pair(1, 1);
    if (Nb == 3) return make_pair(0, 1);
  }
  int Zs = 1 << 2 * Cs, Sf = Zs / 4, Md = 1 << Cs - 1;
  if (Nb < Sf) return Solve(Cs - 1, Nb);
  if (Nb < 2 * Sf) {
    pair<int, int> Res = Solve(Cs - 1, Nb % Sf);
    if (Cs & 1)
      return make_pair(Res.second + Md, Res.first);
    else
      return make_pair(Res.second, Res.first + Md);
  }
  pair<int, int> Res = Solve(Cs, Zs - 1 - Nb);
  if (Cs & 1)
    return make_pair(Res.first, (Md << 1) - 1 - Res.second);
  else
    return make_pair((Md << 1) - 1 - Res.first, Res.second);
}
int main() {
  int a = IN(), b = IN();
  pair<int, int> Ans = Solve(a, b);
  if (a & 1) swap(Ans.first, Ans.second);
  OUT(Ans.first), putchar(' '), OUT(Ans.second);
}
