fun main(args: Array<String>) = yorukatsu9d()

fun yorukatsu9d() {
    val (n, x) = readLine()!!.split(' ').map { it.toLong() }

    val pattyAndBans = LongArray(51)
    pattyAndBans[0] = 1
    for (i in 0 until pattyAndBans.lastIndex) pattyAndBans[i + 1] = pattyAndBans[i] * 2 + 3

    val bans = LongArray(51)
    bans[0] = 1
    for (i in 0 until bans.lastIndex) bans[i + 1] = bans[i] * 2 + 1

    fun dfs(lv: Int, pos: Long): Long {
        if (lv == 0) return 1
        if (pos == 1L) return 0
        if (pos == pattyAndBans[lv]) return bans[lv]
        val mid = pattyAndBans[lv] / 2 + 1
        return when {
            pos < mid -> {
                dfs(lv - 1, pos - 1)
            }
            pos == mid -> {
                bans[lv - 1] + 1
            }
            else -> {
                dfs(lv - 1, pos - mid) + bans[lv - 1] + 1
            }
        }
    }

    val answer = dfs(n.toInt(), x)

    println(answer)
}
