#include <bits/stdc++.h>
using namespace std;
long long n, m, i, f[1010], ans;
int g[1010];
int main() {
  scanf("%I64d%I64d", &n, &m);
  f[0] = 1;
  for (i = 1; i <= n; i++) f[i] = f[i - 1] * 2;
  for (i = 1; i <= n; i++) {
    if (m > f[n - i + 1] / 2) {
      m = m - f[n - i + 1] / 2;
      g[i] = 1;
    }
  }
  ans = n;
  g[0] = 1;
  for (i = 1; i <= n; i++)
    if (g[i] == g[i - 1]) ans = ans + f[n - i + 1] - 1;
  printf("%I64d", ans);
}
