#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, cen;
  long long n, num;
  while (scanf("%d%I64d", &h, &n) != EOF) {
    num = (long long)pow(2.0, h) - 1 + n;
    int flag;
    long long ans = 0;
    if (num % 2 == 0)
      flag = 0;
    else
      flag = 1;
    cen = h - 1;
    while (1) {
      ans++;
      num /= (long long)2;
      if (num % 2 == 0) {
        if (flag == 0) ans += (long long)pow(2.0, h - cen) - (long long)1.0;
        flag = 0;
      } else {
        if (flag == 1) ans += (long long)pow(2.0, h - cen) - (long long)1.0;
        flag = 1;
      }
      if (num == 1) break;
      cen--;
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
