#include <bits/stdc++.h>
using namespace std;
int h;
unsigned long long n, ted, ans;
void solve() {
  ted = 1;
  for (int i = 0; i < h; i++) ted = (unsigned long long)ted * 2;
  bool dir = 0;
  for (; h > 0; h--) {
    ted /= 2;
    if (n <= ted && dir == false)
      ans++;
    else if (n > ted && dir == true) {
      n -= ted;
      ans++;
    } else if (n <= ted && dir == true) {
      dir = !dir;
      ans = (unsigned long long)ans + (unsigned long long)(ted * 2);
    } else {
      dir = !dir;
      ans = (unsigned long long)ans + (unsigned long long)(ted * 2);
      n -= ted;
    }
    dir = !dir;
  }
}
int main() {
  cin >> h >> n;
  solve();
  cout << ans << endl;
  return 0;
}
