#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using LD = long double;
using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pld = pair<LD, LD>;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int h;
  LL n;
  cin >> h >> n;
  LL cur_val = 1;
  bool pos_bval = 1;
  while (h) {
    if (n <= (1LL << h) / 2) {
      if (pos_bval == 1) {
        ++cur_val;
        pos_bval = 0;
      } else {
        cur_val += 1LL << h;
      }
    } else {
      if (pos_bval == 0) {
        ++cur_val;
        pos_bval = 1;
      } else {
        cur_val += 1LL << h;
      }
      n -= 1LL << (h - 1);
    }
    --h;
  }
  cout << --cur_val;
}
