#include <bits/stdc++.h>
using namespace std;
long long n, h;
int main() {
  while (~scanf("%lld%lld", &h, &n)) {
    long long ans = (long long)(pow(2, h + 1)) - 1;
    bool dir_last = false;
    while (h--) {
      bool dir;
      if ((long long)pow(2, h) >= n)
        dir = true;
      else {
        dir = false;
        n -= (long long)pow(2, h);
      }
      if (dir ^ dir_last) ans -= (long long)(pow(2, h + 1)) - 1;
      dir_last = dir;
    }
    printf("%lld\n", ans - 1);
  }
  return 0;
}
