#include <bits/stdc++.h>
int main() {
  long long h, n;
  std::cin >> h >> n;
  long long rez = 0;
  bool pas = 0;
  long long tot;
  tot = (long long)1 << h;
  while (tot) {
    if ((n * 2 <= tot) == pas) {
      rez += tot - 1;
    } else
      pas = !pas;
    rez++;
    if (n * 2 > tot) n -= tot / 2;
    tot /= 2;
  }
  rez--;
  std::cout << rez;
  return 0;
}
