#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
const int MAX = 2e5 + 5;
const long long MAX2 = 11;
const int MOD = 1000000000 + 7;
const long long INF = 20000;
const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
const double pi = acos(-1);
long long n, h, ans;
bool st, ada;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> h >> n;
  n--;
  for (int i = (int)h - 1; i >= (int)0; i--) {
    ada = (1ll << i) & n;
    if (ada ^ st)
      ans += (1ll << (i + 1));
    else
      ans++, st ^= 1;
  }
  cout << ans << "\n";
  return 0;
}
