#include <bits/stdc++.h>
using namespace std;
long long h, n;
bool found = 0;
long long ans = 0;
long long power(long long b, int p) {
  if (p == 0) return 1;
  if (p == 1) return b;
  long long ans = (power(b, p / 2));
  if (p % 2 == 0) return ans * ans;
  return ans * ans * b;
}
void dfs(int d, long long l, long long r, bool q) {
  ans++;
  if (d == 0) {
    if (l == n) found = 1;
    return;
  } else {
    long long mid = (l + r) / 2;
    if (q == 0) {
      if (n <= mid)
        dfs(d - 1, l, mid, 1 - q);
      else {
        ans += (power(2, d) - 1);
        dfs(d - 1, mid + 1, r, q);
      }
    } else {
      if (n > mid)
        dfs(d - 1, mid + 1, r, 1 - q);
      else {
        ans += (power(2, d) - 1);
        dfs(d - 1, l, mid, q);
      }
    }
  }
}
int main() {
  cin >> h >> n;
  dfs(h, 1, power(2, h), 0);
  cout << ans - 1 << endl;
  return 0;
}
