#include <bits/stdc++.h>
using namespace std;
long long cal(long long a, long long b) {
  long long s = 1;
  for (int i = 1; i <= b; ++i) {
    s *= a;
  }
  return s;
}
int main() {
  long long h, n, slast, cnt, ans;
  while (~scanf("%I64d %I64d", &h, &n)) {
    ans = 0;
    cnt = 0;
    int des = 0;
    slast = cal(2, h);
    while (h) {
      slast /= 2;
      if (n > cnt + slast) {
        cnt += slast;
        if (!des) {
          ans = ans + cal(2, h) - 1;
        } else
          des = 1 - des;
      } else {
        if (des) {
          ans = ans + cal(2, h) - 1;
        } else
          des = 1 - des;
      }
      h--;
      ans++;
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
