#include <bits/stdc++.h>
using namespace std;
using namespace std;
long long int fast_expo(long long int base, long long int to) {
  long long int res = 1;
  while (to) {
    if (to & 1) {
      res *= base;
    }
    base *= base;
    to /= 2;
  }
  return res;
}
long long int to_bin[50];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int h, n;
  cin >> h >> n;
  long long int temp = n - 1;
  for (long long int i = 0; i < h; i++) {
    to_bin[h - i - 1] = temp % 2;
    temp /= 2;
  }
  long long int ans = 0;
  if (to_bin[0] == 1) {
    ans += fast_expo(2, h);
  } else {
    ans += 1;
  }
  for (long long int i = 1; i < h; i += 1) {
    if (to_bin[i] == to_bin[i - 1]) {
      ans += fast_expo(2, h - i);
    } else {
      ans += 1;
    }
  }
  cout << ans;
  return 0;
}
