import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;


void main() {
    int n;
    long x;
    scan(n, x);

    auto a = new long[](n + 1); // 長さ
    auto b = new long[](n + 1); // Pの枚数

    a[0] = b[0] = 1;

    foreach (i ; 1 .. n + 1) {
        a[i] = 2L*a[i-1] + 3;
        b[i] = 2L*b[i-1] + 1;
    }

    long query(int L, long x) {
        if (L == 0) {
            return x == 1;
        }
        if (x <= 1) {
            return 0;
        }
        else if (x < (a[L] + 1) / 2) {
            return query(L-1, x - 1);
        }
        else if (x == (a[L] + 1) / 2) {
            return b[L-1] + 1;
        }
        else if (x < a[L] - 1) {
            return b[L-1] + 1 + query(L-1, x - (a[L] + 1) / 2);
        }
        else {
            return 2*b[L-1] + 1;
        }
    }

    long ans = query(n, x);

    writeln(ans);

}


















void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}