#include <bits/stdc++.h>
using namespace std;
int main() {
  long long h, n;
  cin >> h >> n;
  long long ans = 0, num = 1;
  int dir = 1;
  for (int i = 1; i <= h; i++) {
    num *= 2;
  }
  for (int i = 1; i <= h; i++) {
    num /= 2;
    if (n > num) {
      if (dir == 1)
        ans += num * 2;
      else
        ans++;
      n -= num, dir = 1;
    } else {
      if (dir == 0)
        ans += num * 2;
      else
        ans++;
      dir = 0;
    }
  }
  cout << ans << endl;
  return 0;
}
