#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll mod = 1000000007, maxn = 2e5 + 5;
inline ll add(ll a, ll b, ll m) { return (((a % m) + (b % m)) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m) * (b % m)) % m); }
inline ll sub(ll a, ll b, ll m) { return (((a % m) - (b % m) + m) % m); }
ll power(ll a, ll b, ll m) {
  if (a == 0) return 0;
  if (b == 0) return 1;
  if (b == 1) return a;
  ll p = power(a, b / 2, m);
  p = (p * p) % m;
  if (b & 1) p = (p * (a % m)) % m;
  return p;
}
ll fun(ll h, ll n, ll f) {
  if (h == 0) return 0;
  ll p = pow(2, h - 1), pp = pow(2, h) - 1;
  if (n > p) {
    if (f == 0)
      return 1 + pp + fun(h - 1, n - p, f);
    else
      return 1 + fun(h - 1, n - p, !f);
  } else {
    if (f == 1)
      return 1 + pp + fun(h - 1, n, f);
    else
      return 1 + fun(h - 1, n, !f);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll h, n;
  cin >> h >> n;
  cout << fun(h, n, 0);
  return 0;
}
