#include <bits/stdc++.h>
using namespace std;
void solve() {
  int h;
  long long n;
  cin >> h >> n;
  long long cur = 1;
  for (int i = 1; i <= h - 1; i++) {
    cur *= 2ll;
  }
  long long add = cur * 2ll;
  long long cnt = 0;
  int move = 0;
  for (int i = 1; i <= h; i++) {
    if (n <= cur) {
      if (move == 0) {
        cnt++;
      } else {
        cnt += add;
      }
      move = 1;
    } else {
      if (move == 1) {
        cnt++;
      } else {
        cnt += add;
      }
      n -= cur;
      move = 0;
    }
    cur /= 2ll;
    add /= 2ll;
  }
  cout << cnt;
}
int main() {
  if (0) freopen("input.txt", "rt", stdin);
  if (0) freopen("output.txt", "wt", stdout);
  solve();
}
