#include <bits/stdc++.h>
using namespace std;
long long p[55];
long long ans;
long long n;
long long h;
void dfs(long long x, long long lev, long long dir) {
  ans++;
  if (lev == h) return;
  long long a, b, c, e, z, l, r, lch, rch;
  lch = (x - 1) * 2 + 1;
  rch = x * 2;
  if (!dir) {
    l = (lch - 1) * p[h - lev - 1] + 1;
    r = lch * p[h - lev - 1];
    if (n >= l && n <= r) {
      dfs(lch, lev + 1, 1);
    } else {
      ans = ans + ((p[h - lev])) - 1;
      dfs(rch, lev + 1, 0);
    }
  } else {
    l = (rch - 1) * p[h - lev - 1] + 1;
    r = rch * p[h - lev - 1];
    if (n >= l && n <= r) {
      dfs(rch, lev + 1, 0);
    } else {
      ans = ans + ((p[h - lev])) - 1;
      dfs(lch, lev + 1, 1);
    }
  }
}
int main() {
  long long a, b, c, d, e, x, y, z;
  for (a = 0; a <= 52; a++) p[a] = (1LL << a);
  cin >> h >> n;
  ans = 0;
  dfs(1, 0, 0);
  cout << ans - 1 << endl;
  return 0;
}
