#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
  x = 0;
  char ch = getchar();
  long long fh = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') fh = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  x *= fh;
}
template <typename T>
void write(T x) {
  if (x < 0) x = -x, putchar('-');
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
template <typename T>
void writeln(T x) {
  write(x);
  puts("");
}
long long h, n;
long long pwr[55];
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  pwr[0] = 1;
  for (long long i = 1; i <= 50; i++) pwr[i] = pwr[i - 1] * 2;
  cin >> h >> n;
  long long num = pwr[h] + n - 1;
  long long ans = 0;
  long long pre = 1;
  for (long long i = h; i >= 1; i--) {
    if (pre == (num >> (i - 1) & 1)) {
      ans += pwr[i];
    } else {
      ans++;
      pre = (num >> (i - 1) & 1);
    }
  }
  cout << ans << endl;
  return 0;
}
