fun main(args : Array<String>) {
    val (n, x) = readLine()!!.split(" ").map { it.toLong() }
    val burger = LongArray(n.toInt()+1){0L}
    val patty = LongArray(n.toInt()+1){0L}

    burger[0] = 1L
    patty[0] = 1L

    repeat(n.toInt()) {
        burger[it+1] = (2L * burger[it]) + 3L
        patty[it+1] = (2L * patty[it]) + 1L
    }

    fun cal(n: Int, eat: Long): Long {
        if (n == 1) {
            return (when {
                eat >= 4L -> 3L
                eat > 1L -> eat - 1L
                else -> 0L
            })
        }

        if (eat <= 1 + burger[n-1]) {
            return cal(n-1, eat-1)
        } else {
            return patty[n-1] + 1L + cal(n-1, eat - burger[n-1] - 2L)
        }
    }

    println(cal(n.toInt(), x))
}