#include <bits/stdc++.h>
using namespace std;
int main() {
  long long h, n;
  while (cin >> h >> n) {
    long long ans = 1;
    long long hh = h;
    int dir = 0;
    for (int i = 0; i < h; i++, hh--) {
      long long left = (1ll << hh) - 1;
      long long nd = 1ll << (hh - 1);
      if (dir % 2 == 0) {
        if (n > nd) {
          ans += left;
          if (i != h - 1) ans++;
          n -= nd;
        } else {
          dir = 1;
          if (i != h - 1) ans++;
        }
      } else {
        if (n <= nd) {
          ans += left;
          if (i != h - 1) ans++;
        } else {
          dir = 0;
          n -= nd;
          if (i != h - 1) ans++;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
