#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T POW(T B, T P) {
  if (P == 0) return 1;
  if (P & 1)
    return B * POW(B, P - 1);
  else
    return SQR(POW(B, P / 2));
}
template <typename T>
inline T BigMod(T b, T p, T m) {
  if (p == 0) return 1;
  if (p % 2 == 0) {
    T s = BigMod(b, p / 2, m);
    return ((s % m) * (s % m)) % m;
  }
  return ((b % m) * (BigMod(b, p - 1, m) % m)) % m;
}
template <typename T>
inline T ModInv(T b, T m) {
  return BigMod(b, m - 2, m);
}
template <typename T>
inline T ABS(T a) {
  if (a < 0)
    return -a;
  else
    return a;
}
template <typename T>
inline T gcd(T a, T b) {
  if (a < 0) return gcd(-a, b);
  if (b < 0) return gcd(a, -b);
  return (b == 0) ? a : gcd(b, a % b);
}
template <typename T>
inline T lcm(T a, T b) {
  if (a < 0) return lcm(-a, b);
  if (b < 0) return lcm(a, -b);
  return a * (b / gcd(a, b));
}
long long int h, n;
long long int recur(long long int hi, long long int fl, long long int r) {
  if (hi == 0) return 0;
  long long int k, m, sum = 0;
  k = (1LL << hi);
  m = k / 2;
  if (r <= m && fl == 0) {
    return (1LL + recur(hi - 1, 1LL, r));
  } else if (r > m && fl == 0LL) {
    sum += 1LL;
    long long int tm = m;
    while (tm) {
      sum += tm;
      tm /= 2LL;
    }
    return (sum + recur(hi - 1, 0, r - m));
  } else if (r > m && fl == 1) {
    return (1 + recur(hi - 1, 0, r - m));
  } else {
    sum += 1;
    long long int tm = m;
    while (m) {
      sum += m;
      m /= 2;
    }
    return (sum + recur(hi - 1, 1, r));
  }
}
int main() {
  cin >> h >> n;
  long long int res = recur(h, 0LL, n);
  cout << res << endl;
  return 0;
}
