#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n, h;
  cin >> h >> n;
  n--;
  long long cto = 1;
  long long ans = 0;
  for (long long bt = h - 1; bt >= 0; bt--) {
    long long rbt = ((n >> bt) & 1);
    if (rbt == cto) {
      ans += (2LL << bt);
    } else {
      ans++;
    }
    cto = rbt;
  }
  cout << ans << endl;
}
