#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int res = 0LL, n, i = 1LL, trg, x;
  int h, c;
  bool next = 0;
  scanf("%d%I64d", &h, &n);
  trg = (1LL << (long long int)h) - 1LL + n;
  c = 0;
  while (i != trg) {
    x = trg;
    while (x / 2 != i) {
      x /= 2;
    }
    if (x == i * 2) {
      if (next == 0) {
        res++;
        c++;
        i = i * 2;
      } else {
        res += (1LL << (long long int)(h - c));
        i = i * 2;
        c++;
      }
      next = 1;
    } else {
      if (next == 1) {
        res++;
        c++;
        i = i * 2 + 1;
      } else {
        res += (1LL << (long long int)(h - c));
        i = i * 2 + 1;
        c++;
      }
      next = 0;
    }
  }
  printf("%I64d\n", res);
}
