import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "p", long, "dist");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

long[] paty;
long[][] bager;

void main()
{
    long n, k;
    scan(n, k);
    paty ~= 1, bager ~= [1];
    foreach (i; iota(1, n + 1))
    {
        paty ~= 2 * paty[i - 1] + 1;
        bager ~= [1, bager[i - 1].sum(), 1, bager[i - 1].sum(), 1];
    }
    // paty.writeln();
    // bager.writeln();
    long ans;
    solve(ans, n, k);
    ans.writeln();
}

void solve(ref long ans, long depth, long res)
{
    if (res == 0)
    {
        return;
    }
    else if (depth == 0)
    {
        ans += 1;
        return;
    }

    foreach (i, e; bager[depth])
    {
        if (res >= e)
        {
            if(i != 0 && i != bager[depth].length - 1)
                ans += min(e, paty[depth - 1]);
            res -= e;
        }
        else
        {
            solve(ans, depth - 1, res);
            return;
        }
    }
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}
