#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long h, n;
  cin >> h >> n;
  --n;
  long long ans = 0, dir = 0;
  for (long long i = 0; i < h; ++i) {
    ++ans;
    if (dir == 0) {
      if ((n & (1ll << (h - i) - 1)) <= ((1ll << (h - i - 1)) - 1)) {
        dir = 1;
      } else {
        ans += (1ll << (h - i)) - 1;
      }
    } else {
      if ((n & (1ll << (h - i) - 1)) <= ((1ll << (h - i - 1)) - 1)) {
        ans += (1ll << (h - i)) - 1;
      } else {
        dir = 0;
      }
    }
  }
  cout << ans << endl;
}
