#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7fffffff;
int main() {
  long long h, n;
  cin >> h >> n;
  long long t = 1;
  for (int i = 0; i < h; i++) t *= 2;
  long long ans = 0;
  int hehe = 1;
  for (int i = 0; i < h; i++) {
    t /= 2;
    if (n > t) {
      if (hehe == 1)
        ans += t * 2;
      else
        ans++;
      n -= t, hehe = 1;
    } else {
      if (hehe == 0)
        ans += t * 2;
      else
        ans++;
      hehe = 0;
    }
  }
  cout << ans << endl;
  ;
  return 0;
}
