let rec next_value (l:int list) (v:int) = match l with 
  | []   -> None
  | x::c -> if (v=x) then 
      if ((List.length c)>0) then (Some (List.hd c))
      else None
    else next_value c v