#include <bits/stdc++.h>
using namespace std;
long long f(long long nvl, long long leaf, int nxt) {
  if (nvl == 0) return 0;
  long long son = (1LL << nvl);
  if (nxt == 0) {
    if (leaf <= son / 2LL)
      return 1LL + f(nvl - 1, leaf, 1);
    else
      return son + f(nvl - 1, leaf - son / 2LL, 0);
  } else {
    if (leaf <= son / 2LL)
      return son + f(nvl - 1, leaf, 1);
    else
      return 1LL + f(nvl - 1, leaf - son / 2LL, 0);
  }
}
int main() {
  long long nvl, leaf;
  cin >> nvl >> leaf;
  cout << f(nvl, leaf, 0) << endl;
}
