#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  long long int h, n;
  cin >> h >> n;
  n--;
  long long int dir = 0;
  long long int res = 0;
  for (long long int i = 0; i < ((long long int)(h)); i++) {
    res++;
    long long int now = (((1ll << (h - i - 1)) & n) > 0 ? 1 : 0);
    if (dir == now) {
      dir = 1 - dir;
    } else {
      res += (1ll << (h - i)) - 1;
      dir = 1 - now;
    }
  }
  cout << res << endl;
  return 0;
}
