#include <bits/stdc++.h>
using namespace std;
long long n, h, ans = 0;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> h >> n;
  long long temp = ((long long)1 << h);
  int flag = 0;
  while (1) {
    if (h < 0 or temp <= 0) break;
    ans++;
    if (flag == 0) {
      temp /= 2;
      if (n > temp) {
        ans += (((long long)1 << h) - 1);
        n -= temp;
      } else
        flag = 1;
    } else {
      temp /= 2;
      if (n <= temp) {
        ans += (((long long)1 << h) - 1);
      } else
        n -= temp, flag = 0;
    }
    h--;
  }
  cout << ans - 1 << endl;
}
