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 bs = new long[ 1 + n ];
	auto ps = new long[ 1 + n ];
	ps[ 0 ] = 1;
	foreach( i; 0 .. n )
	{
		bs[ i + 1 ] = bs[ i ] * 2 + 2;
		ps[ i + 1 ] = ps[ i ] * 2 + 1;
	}
	
	auto ans = 0L;
	foreach_reverse( i; 1 .. n + 1 )
	{
		auto h = ( bs[ i ] + ps[ i ] ) / 2;
		if( h <= x )
		{
			auto c = h < x;
			ans += ps[ i - 1 ] + c;
			x -= h + c;
			if( x <= 0 ) break;
		}
		else
		{
			x--;
		}
	}
	if( 0 < x ) ans++;
	return ans;
}
