#include <bits/stdc++.h>
using namespace std;
long long h, n, x;
long long ans;
void solve(int lev, bool f = 0) {
  if (lev == 0) {
    cout << ans << endl;
    return;
  }
  if (!f) {
    if (n > (1LL << (long long)(lev - 1))) {
      ans += (1LL << (long long)lev);
      n -= (1LL << (long long)(lev - 1));
      solve(lev - 1, f);
    } else {
      ++ans;
      solve(lev - 1, 1 - f);
    }
  } else {
    if (n <= (1LL << (long long)(lev - 1))) {
      ans += (1LL << (long long)(lev));
      solve(lev - 1, f);
    } else {
      n -= (1LL << (long long)(lev - 1));
      ++ans;
      solve(lev - 1, 1 - f);
    }
  }
}
int main(int argc, char **argv) {
  cin >> h >> n;
  x = n;
  solve(h);
  return 0;
}
