#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const long long MOD = 1e9 + 7;
const double eps = 1e-9;
long long go(long long men, long long mex, int height, long long key,
             bool left) {
  if (!(men <= key and key <= mex)) {
    return (1LL << (height + 1)) - 1;
  }
  if (men == mex and mex == key) return 0;
  if (height == 0) return 1;
  long long mid = (men + mex) >> 1, ans = 1;
  if (left) {
    ans += go(men, mid, height - 1, key, false);
    if (!(men <= key and key <= mid))
      ans += go(mid + 1, mex, height - 1, key, true);
  } else {
    ans += go(mid + 1, mex, height - 1, key, true);
    if (!(mid + 1 <= key and key <= mex))
      ans += go(men, mid, height - 1, key, false);
  }
  return ans;
}
long long h, n;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> h >> n;
  cout << go(0, (1LL << h) - 1, h, n - 1, true) << "\n";
}
