import std.algorithm;
import std.bigint;
import std.bitmanip;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long N, long X) {
    auto w = new long[](N + 1);
    auto p = new long[](N + 1);
    w[0] = p[0] = 1;

    foreach (i; 1 .. N + 1) {
        w[i] = 2 * w[i - 1] + 3;
        p[i] = 2 * p[i - 1] + 1;
    }

    long patties(long level, long x) {
        if (level <= 0)
            return 1;
        if (x <= 1)
            return 0;
        if (x <= 1 + w[level - 1])
            return patties(level - 1, x - 1);
        if (x == 1 + w[level - 1] + 1)
            return p[level - 1] + 1;
        if (x <= w[level] - 1)
            return p[level - 1] + 1 + patties(level - 1, x - (1 + w[level - 1] + 1));
        return p[level - 1] + 1 + p[level - 1];
    } 

    return patties(N, X);
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long N;
    N = input.front.to!long;
    input.popFront;

    long X;
    X = input.front.to!long;
    input.popFront;

    static if (is(ReturnType!solve == void))
        solve(N, X);
    else
        solve(N, X).writeln;
}
