#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  long long h, n;
  while (cin >> h >> n) {
    long long ans = 0;
    bool dir = false;
    for (; h > 0; h--) {
      bool Rit = (n > (1ll << (h - 1)));
      if (Rit == dir) {
        dir = !dir;
        ans++;
      } else
        ans += (1ll << h);
      if (Rit) n -= (1ll << (h - 1));
    }
    cout << ans << endl;
  }
}
