#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = int(1e9);
long long h, n, res, dir;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> h >> n;
  n--;
  for (int i = h - 1; i >= 0; i--) {
    if (n & (1ll << i)) {
      if (dir == 0) {
        res += (1ll << (i + 1));
      } else {
        res++;
        dir ^= 1;
      }
    } else {
      if (dir == 1) {
        res += (1ll << (i + 1));
      } else {
        res++;
        dir ^= 1;
      }
    }
  }
  cout << res << endl;
  return 0;
}
