#include <bits/stdc++.h>
using namespace std;
int main() {
  int h;
  long long n, l = 1, r, rpta = 0, aux2;
  cin >> h >> n;
  r = 1LL << h;
  aux2 = r;
  int aux = 1;
  while (r > l) {
    rpta++;
    long long m = (l + r) / 2;
    if (n <= m && aux == 0) {
      rpta += aux2 - 1;
    } else if (n > m && aux == 1) {
      rpta += aux2 - 1;
    } else
      aux ^= 1;
    if (n <= m)
      r = m;
    else
      l = m + 1;
    aux2 >>= 1;
  }
  cout << rpta << endl;
  return 0;
}
