#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t, n, h, i, ans = 0, j, x, y, num;
  cin >> h >> n;
  ans = 0;
  num = pow(2, h);
  char ch = 'L';
  while (h--) {
    if ((n > (num / 2) && ch == 'R') || (n <= (num / 2) && ch == 'L'))
      ans++;
    else
      ans += num;
    if (n > (num) / 2) {
      n -= num / 2;
      ch = 'L';
    } else
      ch = 'R';
    num /= 2;
  }
  cout << ans << endl;
}
