#include <bits/stdc++.h>
using namespace std;
long long h, n, a, num = 1, ans;
void input() { cin >> n >> h; }
void solve() {
  h += pow(2, n) - 1;
  a = h % 2;
  h /= 2;
  while (h) {
    if (h % 2 == a)
      ans += pow(2, num);
    else
      ans += 1;
    a = h % 2;
    h /= 2;
    num++;
  }
  cout << ans;
}
int main() { input(), solve(); }
