#include <bits/stdc++.h>
using namespace std;
long long n, h, ans = 0;
int s[60];
int main() {
  int i, j, num;
  long long temp = 1;
  scanf("%lld%lld", &h, &n);
  for (i = 0; i < h; i++) temp *= 2;
  temp = temp - 1 + n;
  num = 0;
  while (temp > 1) {
    s[num++] = temp % 2 ? -1 : 1;
    temp /= 2;
  }
  int flag = 1;
  for (i = num - 1; i >= 0; i--) {
    if (flag == s[i]) {
      ans++;
      flag = -flag;
    } else {
      temp = 1;
      for (j = 0; j <= i; j++) temp *= 2;
      ans += temp;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
