#include <bits/stdc++.h>
using namespace std;
long long f(long long lvl, long long n, int t) {
  if (lvl == 0) return 0;
  if (t == 0) {
    if (n <= (1LL << (lvl - 1))) return 1 + f(lvl - 1, n, 1);
    return (1LL << lvl) + f(lvl - 1, n - (1LL << (lvl - 1)), 0);
  }
  if (n <= (1LL << (lvl - 1))) return (1LL << lvl) + f(lvl - 1, n, 1);
  return 1 + f(lvl - 1, n - (1LL << (lvl - 1)), 0);
}
int main() {
  long long lvl, n;
  while (cin >> lvl >> n) {
    cout << f(lvl, n, 0) << '\n';
  }
}
