#include <bits/stdc++.h>
using namespace std;
long long h, n, k, pre, ans;
int main() {
  scanf("%lld%lld", &h, &n);
  long long ans = (1ll << h + 1) - 1;
  pre = 1;
  while (h--) {
    if ((1ll << h) >= n)
      k = -1;
    else
      n -= (1ll << h), k = 1;
    if (pre * k == -1) ans -= (1ll << h + 1) - 1;
    pre = k;
  }
  printf("%lld\n", ans - 1);
  return 0;
}
