#include <bits/stdc++.h>
using namespace std;
long long cntr(long long x) {
  long long t = 62;
  while (t > 0) {
    if ((1LL << t) <= x) return t + 1;
    t--;
  }
  return 0;
}
long long gen(int len, long long st) {
  long long r = 0;
  for (int i = 0; i < len; i++) {
    r = (r << 1) | st;
    st = !st;
  }
  return r;
}
long long walk(long long st, long long dep, long long h, long long tar) {
  if (dep == h) return 1;
  long long x = 1LL << (h - dep - 1);
  if (((tar & x) > 0) != st)
    return walk(st, dep + 1, h, tar) + x * 2 - 1 + 1;
  else
    return walk(!st, dep + 1, h, tar) + 1;
}
int main() {
  int h;
  long long n;
  scanf("%d%I64d", &h, &n);
  n--;
  printf("%I64d\n", walk(0, 0, h, n) - 1);
}
