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