#include <bits/stdc++.h>
using namespace std;
int judge(long long curr, long long goal) {
  if (goal == curr) return 1;
  while (goal > 0) {
    if (goal & 1)
      goal--;
    else {
      goal >>= 1;
      if (curr == goal) return 1;
    }
  }
  return 0;
}
long long get(long long h, long long curr) {
  int t = 0;
  while (curr) {
    curr >>= 1;
    t++;
  }
  t = h - t + 1;
  return (((long long)1 << t) - 1);
}
int main() {
  long long h, n;
  while (scanf("%lld%lld", &h, &n) != EOF) {
    h++;
    long long goal = n + ((long long)1 << (h - 1)) - 1;
    long long curr = 1, tot = 0;
    int cho = 0;
    for (int i = 1; i < h; ++i) {
      curr = curr << 1;
      curr += cho;
      cho = !cho;
      if (judge(curr, goal))
        tot++;
      else {
        tot += get(h, curr);
        tot++;
        if (curr % 2 == 0) {
          curr++;
          cho = 0;
        } else {
          curr--;
          cho = 1;
        }
      }
    }
    printf("%lld\n", tot);
  }
  return 0;
}
