fun main(args: Array<String>) {
    val (N, X) = readLine()!!.split(" ").map{it.toLong()}

    val t = Array(60) { 0L }
    val p = Array(60) { 0L }

    t[0] = 1
    p[0] = 1
    for (i in 1 until t.size) {
        t[i] = t[i - 1] * 2 + 3
        p[i] = p[i - 1] * 2 + 1
    }

    fun rec(n: Int, x: Long): Long {
        if (t[n] <= x) {
            return p[n]
        }

        if (n == 0) {
            return 0L
        }

        var r = 0L

        if (x < t[n - 1] + 1) {
            r += rec(n - 1, x - 1)
        }

        if (x >= t[n - 1] + 1) {
            r += p[n - 1]
        }

        if (x >= t[n - 1] + 2) {
            r += 1L
        }

        if (x > t[n - 1] + 2) {
            r += rec(n - 1, x - t[n - 1] - 2)
        }

        return r
    }

    println(rec(N.toInt(), X))
}
