#include<iostream>
using namespace std;
string barger[51];
long long p[51];
long long rinrin(int n, long long x) {
    if (x == 1) { //if n is not 0, last is B, and n is not 0
        return 0;
    } else if (x > 1 && x <= 1 + barger[n - 1].length() - 1) { //1 +'s 1 is first B
        return rinrin(n - 1, x - 1);
    } else if (x == 2 + barger[n - 1].length() - 1) { //2 +'s 2 are first B and center P
        return p[n - 1] + 1;
    } else if (2 + barger[n - 1].length() - 1 < x && x <= 2 + 2 * (barger[n - 1].length() - 1)) {
        return p[n - 1] + 1 + rinrin(n - 1, x - 1 - (barger[n - 1].length() - 1 + 1)); //the rest
    } else /*if (x == 3 + 2 * barger[n - 1].length() - 1)*/ {
        return 2 * p[n - 1] + 1;
    }
}
int main() {
    barger[0] = "P";
    p[0] = 1; //firstly p
    int n;
    long long x; // ~9*10^8
    cin >> n >> x;
    for (int i = 1; i <= n; i++) {
        barger[i] = "B" + barger[i - 1] + "P" + barger[i - 1] + "B";
        p[i] = 2 * p[i - 1] + 1;
    }
    cout << rinrin(n, x) << endl;
}
