#include <bits/stdc++.h>
using namespace std;
string S;
inline string x1(string s) {
  string ret;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'U') ret += 'R';
    if (s[i] == 'R') ret += 'U';
    if (s[i] == 'D') ret += 'L';
    if (s[i] == 'L') ret += 'D';
  }
  return ret;
}
inline string x2(string s) {
  string ret;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'U') ret += 'L';
    if (s[i] == 'R') ret += 'D';
    if (s[i] == 'D') ret += 'R';
    if (s[i] == 'L') ret += 'U';
  }
  return ret;
}
string f(int a) {
  if (a == 1) return "URD";
  return x1(f(a - 1)) + "U" + f(a - 1) + "R" + f(a - 1) + "D" + x2(f(a - 1));
}
int main() {
  ios::sync_with_stdio(0);
  int a, b;
  cin >> a >> b;
  S = f(a);
  int x = 0, y = 0;
  for (int i = 0; i < b; i++) {
    if (S[i] == 'U') y++;
    if (S[i] == 'D') y--;
    if (S[i] == 'L') x--;
    if (S[i] == 'R') x++;
  }
  cout << x << " " << y << endl;
  return 0;
}
