#include <bits/stdc++.h>
int main() {
  int h;
  long long n;
  scanf("%d%I64d", &h, &n);
  long long x = 1LL << (h - 1), ans = 0;
  while (x) {
    ++ans;
    if (n > x) {
      n -= x;
      ans += x * 2 - 1;
    } else {
      n = x - n + 1;
    }
    x >>= 1;
  }
  printf("%I64d\n", ans);
  return 0;
}
