#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100;
long long f(long long h, long long k, long long c) {
  if (h == 0) return 0;
  long long aux = 1ll << (h - 1);
  if (c == 0) {
    if (k <= aux)
      return 1 + f(h - 1, k, 1);
    else {
      return 1 + (1ll << h) - 1 + f(h - 1, k - aux, 0);
    }
  } else {
    if (k <= aux)
      return 1 + (1ll << h) - 1 + f(h - 1, k, 1);
    else
      return 1 + f(h - 1, k - aux, 0);
  }
}
long long h, n;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> h >> n;
  cout << f(h, n, 0) << endl;
  return 0;
}
