#include <bits/stdc++.h>
using namespace std;
int main() {
  int h;
  long long n;
  while (~scanf("%d%I64d", &h, &n)) {
    --n;
    long long ans = 0;
    int pre = 1;
    for (int i = 0; i < h; ++i) {
      int c;
      if (n & (1LL << (h - i - 1))) {
        c = 1;
      } else {
        c = 0;
      }
      if (c != ((pre + 1) & 1)) {
        ans += (1LL << (h - i));
      } else {
        ++ans;
      }
      pre = c;
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
