#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  long long h, n;
  while (cin >> h >> n) {
    long long ans = 0;
    n = (1LL << h) + n - 1;
    long long height_actual = h;
    while (height_actual > 0) {
      long long father = (n % 2 == 0) ? n / 2 : (n - 1) / 2;
      bool left_son = (n % 2 == 0);
      long long cur = 0;
      if ((father % 2 == 0 && left_son) || (father % 2 != 0 && !left_son)) {
        for (int i = height_actual, x = 0; i <= h; i++, x++) cur += (1LL << x);
        ans += cur;
      }
      n = father;
      height_actual--;
    }
    cout << ans + h << endl;
  }
  return 0;
}
