fun burger_count(lv:Int):Pair<Long,Long>{
    if(lv == 0){
      return Pair(1L, 1L);
    }
    val (patty,all) = burger_count(lv - 1);
    return Pair(patty * 2 + 1L, all * 2 + 3L);
}
fun eat_patty(lv:Int,remain_eat:Long):Pair<Long,Long>{
  if (remain_eat == 0L){
    return Pair(0,0);
  }
  if(lv == 0){
    return Pair(1,remain_eat-1);
  }
  else{
    if (remain_eat < 1){
      return Pair(0,0);
    }else{
      val (p,a) = burger_count(lv - 1);
      if(a * 2 < remain_eat - 3){
        return Pair(p * 2 + 1,remain_eat - 3 - (a * 2));
      }else if(a <= remain_eat - 2){
         val (peatedd,rd) = eat_patty(lv - 1,remain_eat - 2 - a);
         return Pair(p + peatedd + 1,rd);
      }else{
         return eat_patty(lv - 1,remain_eat - 1);
      }
    }
  }  
}


fun main(args: Array<String>) {
    val (n,x) = readLine()!!.split(" ").map { num ->num.toLong() };   
    
    val (eat,all) = eat_patty(n.toInt(),x);
    
    println(eat);
}