import std.stdio;
import std.algorithm;
import std.conv;
import std.datetime;
import std.numeric;
import std.math;
import std.string;

string my_readln() { return chomp(readln()); }

void main()
{//try{
	auto tokens = split(my_readln());
	auto N = to!ulong(tokens[0]);
	auto X = to!ulong(tokens[1]);

	ulong[2][] memo;
	memo ~= [1, 1];
	foreach (i; 0..N+1)
	{
		memo ~= [memo[i][0] * 2 + 3, memo[i][1] * 2 + 1];
	}

	ulong f(ulong lv, ref ulong remain)
	{
		if (remain == 0) return 0;
		if (lv == 0) return 1;

		ulong r;
		--remain;

		if (remain < memo[lv-1][0])
			r += f(lv-1, remain);
		else
		{
			r      += memo[lv-1][1];
			remain -= memo[lv-1][0];
		}
		if (remain == 0) return r;

		--remain;
		++r;
		if (remain == 0) return r;

		if (remain < memo[lv-1][0])
			r += f(lv-1, remain);
		else
		{
			r      += memo[lv-1][1];
			remain -= memo[lv-1][0];
		}
		if (remain == 0) return r;

		--remain;

		return r;
	}

	auto result = f(N, X);

	writeln(result);
	stdout.flush();
/*}catch (Throwable e)
	{
		writeln(e.toString());
	}
readln();*/
}