#include <bits/stdc++.h>
long long int power(long long int x, long long int y) {
  long long int temp, ty, my;
  if (y == 0) return 1;
  temp = power(x, y / 2);
  ty = (temp) * (temp);
  if (y % 2 == 0) {
    return ty;
  } else {
    my = (x) * (ty);
    return my;
  }
}
int main() {
  long long int n;
  long long int h;
  scanf("%lld %lld", &h, &n);
  long long int t = n - 1;
  int binary[1000];
  long long int j = 0;
  for (int i = 0; i < h; i++) {
    binary[h - i - 1] = t % 2;
    t = t / 2;
  }
  long long int i = j - 1;
  long long int flip = 1;
  long long int count = 0;
  if (binary[0] == 1) {
    count += power(2, h);
  } else {
    count += 1;
  }
  for (int i = 1; i < h; i++) {
    if (binary[i - 1] != binary[i]) {
      flip = flip ^ 1;
      count++;
    } else {
      count += power(2, h - i);
      flip = flip ^ 1;
    }
  }
  printf("%lld\n", count);
  return 0;
}
