fun longList() = readLine()?.split(" ")?.map(String::toLong) ?: TODO()
fun main() {
    val (n, x) = longList()
    val ni = n.toInt()
    val m = Array(n.toInt() + 1) { 0L }
    fun create(l: Int): Long {
        if (l == 0) {
            return 1
        }
        if (m[l] > 0L) {
            return m[l]
        }
        return (create(l - 1) * 2 + 3).also {
            m[l] = it
        }
    }

    fun eatCount(n: Int, x: Long): Long {
        if (n < 0) {
            return 0L
        }
        val layer = create(n)
        if (x == layer) {
            return layer / 2 + 1
        }
        val center = layer / 2;
        return when {
            x <= center -> {
                eatCount(n - 1, x - 1)
            }
            x == center + 1 -> {
                return center / 2 + 1
            }
            else -> {
                eatCount(n - 1, center - 1) + eatCount(n - 1, x - center - 1) + 1
            }
        }
    }
    println(eatCount(ni, x).toString())
}
