#include <bits/stdc++.h>
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
using namespace std;
long long n, m;
vector<long long> a, used;
vector<vector<long long>> g;
long long ans = 0;
void dfs(long long v, long long k) {
  used[v] = 1;
  long long kn = k;
  if (a[v])
    kn++;
  else
    kn = 0;
  if (kn > m) return;
  if (v != 0 && g[v].size() == 1) {
    ans++;
  }
  for (auto it : g[v]) {
    if (!used[it]) dfs(it, kn);
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long h, n;
  cin >> h >> n;
  n--;
  long long ans = 0;
  long long o = 0;
  long long l = 0, r = (1ll << h);
  for (long long i = 0; i < h; ++i) {
    long long m = (l + r) / 2;
    if (o == 0) {
      if (n >= m) {
        ans += (1ll << (h - i));
        l = m;
      } else {
        ans++;
        r = m;
        o = 1 - o;
      }
    } else {
      if (n < m) {
        ans += (1ll << (h - i));
        r = m;
      } else {
        ans++;
        l = m;
        o = 1 - o;
      }
    }
  }
  cout << ans;
}
