fun main(arr:Array<String>) {
    dic.add(1)
    patDic.add(1)
    for(i in (1..50)) {
        dic.add(dic.last() * 2 + 3)
        patDic.add(patDic.last() * 2 + 1)
    }
    val (n,x) = readLine()!!.split(" ").map { it.toLong() }
    val ans = getAns(x, n.toInt())
    println(ans)
}

fun getAns(remain:Long, depth:Int):Long {
    if(remain == 0L) {
        return 0
    }
    if(depth == 0) {
        return 1
    }
    if(remain - 1 <= dic[depth - 1]) {
        return getAns(remain - 1, depth - 1)
    }
    if(remain - 1 == dic[depth-1] + 1 ) {
        return patDic[depth-1] + 1
    }
    if(remain - 1 < dic[depth-1]*2 + 1) {
        return patDic[depth-1] + 1 + getAns(remain - 2 - dic[depth-1], depth - 1)
    }
    return patDic[depth]
}

val dic = mutableListOf<Long>()
val patDic = mutableListOf<Long>()

