#include <bits/stdc++.h>
const int MAX_LEN = 1010;
using namespace std;
template <typename U, typename V>
string to_string(pair<U, V>);
string to_string(const string& e_) { return "\"" + e_ + "\""; }
string to_string(char e_) { return "\'" + string(1, e_) + "\'"; }
string to_string(bool e_) { return e_ ? "true" : "false"; }
template <typename T>
string to_string(T e_) {
  string s_ = "[ ";
  for (const auto& x_ : e_) s_ += to_string(x_) + " ";
  return s_ + "]";
}
template <typename U, typename V>
string to_string(pair<U, V> e_) {
  return "(" + to_string(e_.first) + ", " + to_string(e_.second) + ")";
}
void dbg_str() { ; }
template <typename U, typename... V>
void dbg_str(U u, V... v) {
  ;
  dbg_str(v...);
}
int a, b;
pair<int, int> solve(int n, int m) {
  if (n == 0) {
    return make_pair(0, 0);
  }
  int len = 1 << (n - 1), mod = 1 << (2 * n - 2), kase;
  pair<int, int> tmp = solve(n - 1, m % mod);
  int x = tmp.first, y = tmp.second;
  kase = m / mod;
  switch (kase) {
    case 1:
      return pair<int, int>(x, y + len);
      break;
    case 2:
      return pair<int, int>(x + len, y + len);
      break;
    case 0:
      return pair<int, int>(y, x);
      break;
    case 3:
      return pair<int, int>(2 * len - y - 1, len - x - 1);
      break;
  }
}
int main() {
  scanf("%d%d", &a, &b);
  pair<int, int> ans = solve(a, b);
  printf("%d %d\n", ans.first, ans.second);
}
