#include <bits/stdc++.h>
using namespace std;
long long n, d, l;
long long ans = 0;
bool search_m(long long l, long long r, long long f) {
  if (l == d && r == d) {
    ans++;
    return true;
  }
  if (r < d || l > d) {
    ans += (r - l + 1) * 2 - 1;
    return false;
  } else {
    long long mid = (l + r) >> 1;
    ans++;
    if (f == 0) {
      if (search_m(l, mid, 1)) return true;
      return search_m(mid + 1, r, 0);
    } else {
      if (search_m(mid + 1, r, 0)) return true;
      return search_m(l, mid, 1);
    }
  }
}
int main() {
  long long i, j, k, x, y, z;
  scanf(
      "%I64d"
      "%I64d",
      &n, &d);
  l = 1ll << n;
  search_m(1, l, 0);
  printf(
      "%I64d"
      "\n",
      ans - 1);
}
