object Main {
  def main(args: Array[String]) {
    val input = io.Source.stdin.getLines()
    println(solve(input))
  }

  def solve(input: Iterator[String]): AnyVal = {
    val Array(n, x) = input.next().split(" ").map(_.toLong)

    def burgerSize(l: Int): Long =
      (1L << (l + 2)) - 3

    def pattySize(l: Int): Long =
      (1L << (l + 1)) - 1

    def rec(x: Long, l: Int): Long = {
      val burgerL1 = burgerSize(l - 1)
      
      if (l == 0 && x >= 1)
        return 1

      if (l == 0)
        return 0

      if (x <= 1)
        return 0


      if (x <= burgerL1 + 1) {
        rec(x - 1, l - 1)
      } else if (x == burgerL1 + 2) {
        1 + pattySize(l - 1)
      } else {
        1 + pattySize(l - 1) + rec(x - burgerSize(l - 1) - 2, l - 1)
      }
    }

    rec(x, n.toInt)
  }
}