#include <bits/stdc++.h>
using namespace std;
long long h, n, ans;
long long p(int n) {
  long long x = 1;
  for (int i = 0; i < n; i++) x *= 2;
  return x;
}
long long f(long long h, long long n, bool napr) {
  if (h == 0) return 0;
  if (n <= (p(h - 1))) {
    if (!napr)
      return (1ll + f(h - 1ll, n, !napr));
    else
      return (p(h) + f(h - 1ll, n, napr));
  } else {
    if (napr)
      return (1ll + f(h - 1ll, n - (p(h - 1ll)), !napr));
    else
      return (p(h) + f(h - 1ll, n - (p(h - 1ll)), napr));
  }
}
int main() {
  cin >> n >> h;
  cout << f(n, h, false);
  return 0;
}
