#include <bits/stdc++.h>
using namespace std;
long long h, n, ans, i, l, r, sza, a[50], k, m, p;
int main() {
  cin >> h >> n;
  a[0] = 1;
  for (i = 1; i <= h; ++i) a[i] = a[i - 1] * 2;
  l = 1;
  r = a[h];
  k = h;
  p = 0;
  while (l != r) {
    ++ans;
    m = (l + r) / 2;
    if (p % 2 == 0) {
      if (n <= m) {
        r = m;
        ++p;
      } else {
        ans += a[k] - 1;
        l = m + 1;
      }
    } else {
      if (n <= m) {
        r = m;
        ans += a[k] - 1;
      } else {
        l = m + 1;
        ++p;
      }
    }
    --k;
  }
  cout << ans;
}
