let rec exist lst = match lst with | [] -> true | h :: t -> if h <> 3 then false else exist t let () = let n = Scanf.scanf "%d\n" (fun x -> x) in let list_of_string str = let l = String.length str in let rec iter i lst = if i >= l then lst else iter (i+1) ((int_of_char str.[i] - 48) :: lst) in iter 0 [] in let slst = List.rev (list_of_string (string_of_int n)) in let head = List.hd slst in let tail = List.tl slst in let n = if head = 1 && (exist tail) then List.length tail else -1 in Printf.printf "%d\n" n