#include <bits/stdc++.h>
using namespace std;
long long ans = 0;
int cur;
long long h, n;
int main() {
  cin >> h >> n;
  long long all = (1LL << h);
  int cur = 1;
  all /= 2;
  while (all > 0) {
    cur ^= 1;
    if (n <= all && cur == 0) {
      ans++;
      all /= 2;
      continue;
    }
    if (n > all && cur == 0) {
      ans += all * 2;
      n -= all;
      all /= 2;
      cur ^= 1;
      continue;
    }
    if (n > all) {
      ans++;
      n -= all;
      all /= 2;
      continue;
    }
    ans += all * 2;
    all /= 2;
    cur ^= 1;
  }
  cout << ans << endl;
  return 0;
}
