#include <bits/stdc++.h>
using namespace std;
const int MAXN = 60;
long long h, n;
int step[MAXN];
inline long long calc(long long high) { return (1ll << (high + 1)) - 1; }
void solve() {
  long long tmp = (1ll << h) - 1 + n;
  int cnt = 0;
  while (tmp != 1) {
    if (tmp % 2 == 1)
      step[cnt++] = 1;
    else
      step[cnt++] = 0;
    tmp /= 2;
  }
  long long res = 0;
  int curdir = 0, dep = 0;
  for (int i = cnt - 1; i >= 0; i--) {
    if (curdir == step[i]) {
      dep++;
      res++;
      curdir ^= 1;
    } else {
      long long tmp = calc(h - dep - 1);
      res += tmp;
      curdir = step[i];
      i++;
    }
  }
  cout << res << endl;
}
int main() {
  cin >> h >> n;
  solve();
  return 0;
}
