import java.io.*
import java.lang.RuntimeException

val pw = PrintWriter(System.out)
const val MOD = 1000000007L
const val INF = 2147483647
const val LINF = 9223372036854775807L

fun main(args: Array<String>) {
    solve()
    pw.flush()
}

fun solve() {
    val (n, x) = nextLongList()
    layer[0] = 1
    pan[0] = 1
    layerCount(1, n)
    panCount(1, n)

    val ans = check(n, n, x)
    println(ans)
}

fun check(now: Long, n: Long, rest: Long): Long{
    if(now == 0L) return pan[0]
    val lastLayer = layer[now.toInt() - 1]

    if(rest == 1L){
        return 0L
    } else if(rest >= 2 && rest <= lastLayer + 1){
        return check(now - 1, n, rest - 1)
    } else if(rest == lastLayer + 2){
        return pan[now.toInt() - 1] + 1
    } else if(rest >= lastLayer + 3 && rest <= lastLayer * 2 + 2){
        return pan[now.toInt() - 1] + 1 + check(now - 1, n, rest - lastLayer - 2)
    } else {
        return pan[now.toInt() - 1] * 2 + 1
    }

}

val layer = Array(51) { 0L }
fun layerCount(now: Long, n: Long){
    if(now > n) return
    layer[now.toInt()] = layer[now.toInt() - 1] * 2 + 3
    layerCount(now + 1, n)
}

val pan = Array(51) { 0L }
fun panCount(now: Long, n: Long){
    if(now > n) return
    pan[now.toInt()] = pan[now.toInt() - 1] * 2L + 1L
    panCount(now + 1L, n)
}


fun println(v: String) {
    pw.println(v)
}

fun print(v: String) {
    pw.print(v)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ").toMutableList()
fun nextIntList(index: Int = 0) = next().split(" ").map { it.toInt() + index }.toMutableList()
fun nextLongList(index: Long = 0L) = next().split(" ").map { it.toLong() + index }.toMutableList()
fun nextDoubleList() = next().split(" ").map { it.toDouble() }.toMutableList()

fun ary(n: Int, init: String = "") = Array(n) { init }
fun intAry(n: Int, init: Int = 0) = IntArray(n) { init }
fun longAry(n: Int, init: Long = 0L) = LongArray(n) { init }
fun doubleAry(n: Int, init: Double = 0.0) = DoubleArray(n) { init }
fun ary2(n: Int, m: Int, init: String = "") = Array(n) { Array(m) { init } }
fun intAry2(n: Int, m: Int, init: Int = 0) = Array(n) { IntArray(m) { init } }
fun longAry2(n: Int, m: Int, init: Long = 0) = Array(n) { LongArray(m) { init } }
fun doubleAry2(n: Int, m: Int, init: Double = 0.0) = Array(n) { DoubleArray(m) { init } }
fun ary3(n: Int, m: Int, k: Int, init: String = "") = Array(n) { Array(m) { Array(k) { init } } }
fun intAry3(n: Int, m: Int, k: Int, init: Int = 0) = Array(n) { Array(m) { IntArray(k) { init } } }
fun longAry3(n: Int, m: Int, k: Int, init: Long = 0L) = Array(n) { Array(m) { LongArray(k) { init } } }
fun doubleAry3(n: Int, m: Int, k: Int, init: Double = 0.0) = Array(n) { Array(m) { DoubleArray(k) { init } } }

fun abs(n: Int): Int = Math.abs(n)
fun abs(n: Long): Long = Math.abs(n)
fun abs(n: Double): Double = Math.abs(n)
fun max(vararg values: Int) = if (values.isEmpty()) -INF else values.max()!!
fun max(vararg values: Long) = if (values.isEmpty()) -LINF else values.max()!!
fun min(vararg values: Int) = if (values.isEmpty()) INF else values.min()!!
fun min(vararg values: Long) = if (values.isEmpty()) LINF else values.min()!!
fun swap(a: String, b: String) = Pair<String, String>(b, a)
fun swap(a: Int, b: Int) = Pair<Int, Int>(b, a)
fun swap(a: Long, b: Long) = Pair<Long, Long>(b, a)
fun swap(a: Double, b: Double) = Pair<Double, Double>(b, a)

Measured memory_bytes: 37772