object Main extends App {
	private def direct(a: Int, n: Int): Long = {
		//val pow = Math.pow(2, n).toLong
		val pow = 1L << n
		pow + a * (pow - 1)
	}

	//@scala.annotation.tailrec
	private def func(n: Int, x: Long): Long = {
		//println("func", n, x)
		if (n == 0 && x > 0) return 1L
		if (x <= 1) return 0L
		//if (n == 0 && x == 0) return 0L

		val lenOfN1 = direct(3, n - 1)
		val numOfN1 = direct(1, n - 1)

		if (x <= lenOfN1 + 1) {
			func(n - 1, x - 1)
		} else {
			numOfN1 + 1 + func(n - 1, x - 2 - lenOfN1)
		}
	}

	private def solve(in: Seq[Long]): Long = func(in(0).toInt, in(1))

	assert(solve(Seq(0, 0)) == 0)
	assert(solve(Seq(0, 1)) == 1)
	assert(solve(Seq(1, 1)) == 0)
	assert(solve(Seq(3, 14)) == 7)
	assert(solve(Seq(3, 15)) == 8)
	assert(solve(Seq(3, 28)) == 15)
	assert(solve(Seq(3, 29)) == 15)
	assert(solve(Seq(50, 4321098765432109L)) == 2160549382716056L)
	println(solve(io.Source.stdin.getLines.toIndexedSeq.head.split(' ').map(_.toLong)))
}
