#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  long long n;
  int h;
  cin >> h >> n;
  n--;
  long long ans = 0;
  long long cnt = ((long long)1 << (h - 1));
  bool to = 0;
  for (int i = 0; i < h; i++) {
    ans++;
    if (n >= cnt) {
      n -= cnt;
      if (!to) ans += 2 * cnt - 1;
      to = 0;
    } else {
      if (to) ans += 2 * cnt - 1;
      to = 1;
    }
    cnt /= 2;
  }
  cout << ans;
  return 0;
}
