unittest
{
	assert( [ "2 7" ].solve == 4 );
	assert( [ "1 1" ].solve == 0 );
	assert( [ "50 4321098765432109" ].solve == 2160549382716056 );
}



import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = 0L;
	auto x = 0L;
	input.front.formattedRead!"%s %s"( n, x );
	
	auto ps = new long[ 1 + n ];
	auto bs = new long[ 1 + n ];
	ps[ 0 ] = 1;
	foreach( i; 0L .. n )
	{
		ps[ i + 1 ] = ps[ i ] * 2 + 1;
		bs[ i + 1 ] = bs[ i ] * 2 + 2;
	}
	
	return solve2( ps, bs, n, x );
}

auto solve2( long[] ps, long[] bs, long n, ref long x )
{
	auto t = 0L;
	if( ps[ n ] + bs[ n ] <= x )
	{
		t += ps[ n ];
		x -= ps[ n ] + bs[ n ];
	}
	else
	{
		if( x == 0 ) return t;
		x--;
		if( x == 0 ) return t;
		t += solve2( ps, bs, n - 1, x );
		if( x == 0 ) return t;
		t++;
		x--;
		if( x == 0 ) return t;
		t += solve2( ps, bs, n - 1, x );
		if( x == 0 ) return t;
		x--;
	}
	return t;
}
