#include <bits/stdc++.h>   using namespace std;   long long n, h, ok;   long long cal(long long dep, long long pos, int tag) {     if (ok) return 0;     if (dep == 0) {       ok = 1;       return 0;     }     long long tmp;     if (!tag) {       if (pos > (1LL << (dep - 1)))         tmp = (1LL << dep) + cal(dep - 1, pos - (1LL << (dep - 1)), 0);       else         tmp = 1LL + cal(dep - 1, pos, 1);     } else {       if (pos > (1LL << (dep - 1)))         tmp = 1LL + cal(dep - 1, pos - (1LL << (dep - 1)), 0);       else         tmp = (1LL << dep) + cal(dep - 1, pos, 1);     }     return tmp;   }   int main() {     while (cin >> h >> n) {       ok = 0;       cout << cal(h, n, 0) << endl;     }   }   