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