object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val N = sc.nextInt()
  val X = sc.nextLong()
  def makeDat(count:Int,d:List[Long],add:Long):List[Long]={
    count match {
      case 0 => d
      case _ => makeDat(count-1,d.head*2+add::d,add)
    }
  }
  val layer = makeDat(50,1::Nil,3)
  val patty = makeDat(50,1::Nil,1)
  def l(level:Int)= layer(50-level)
  def p(level:Int)= patty(50-level)
  def ans(n:Int,x:Long):Long={
    if(n==0) 1
    else if(x == 1) 0
    else if(x <  1 + l(n-1)) ans(n-1,x-1)
    else if(x == 1 + l(n-1)) p(n-1)
    else if(x == 2 + l(n-1)) p(n-1) + 1
    else if(x <  2 + l(n-1)*2) p(n-1) + 1 + ans(n-1,x-2-l(n-1))
    else l(n)
  }
  println(ans(N,X))
}