#include <bits/stdc++.h>
using namespace std;
int main() {
  int h;
  cin >> h;
  long long n;
  cin >> n;
  n--;
  long long ret = 0;
  ret = h;
  int x = 0;
  for (int i = 0; i < h; i++) {
    if (x != ((n >> (h - i - 1)) & 1)) ret += (1ll << (h - i)) - 1;
    x = 1 - ((n >> (h - i - 1)) & 1);
  }
  cout << ret << endl;
}
