Scanf.(Array.(
  let n,x=scanf" %d %d"@@fun u v->u,v in
  let s,p=make 50 1,make 50 1 in
  init 49 (fun i->
    s.(i+1)<-2*s.(i)+3;
    p.(i+1)<-2*p.(i)+1) |> ignore;
  let rec f lv ofs =
    (* if lv=1 then (
      if ofs=1 then 0
      else if ofs=5 then 3
      else ofs-1 *)
    if lv=0 then (
      assert (ofs=1); 1
      (* if ofs=1 then 1 else 0 *)
    ) else (
      let r=s.(lv-1) in
      if ofs=1 then 0
      else if ofs<=1+r   then f (lv-1) (ofs-1)
      else if ofs =2+r   then 1 + f (lv-1) r
      else if ofs<=2+r+r then 1 + f (lv-1) r + f (lv-1) (ofs-2-r)
      else if ofs =3+r+r then 1 + 2 * f (lv-1) r
      else failwith ""
    )
  in print_int @@ f n x
));;