let rec drop n xs =
  if n = 0
  then xs
  else drop (n - 1) (List.tl xs)

exception Exit of int list

let () = Scanf.scanf "%d %d\n" @@ fun n m ->
  let es = Array.make n [] in
  for i = 0 to m - 1 do
    Scanf.scanf "%d %d\n" @@ fun a b ->
      es.(a - 1) <- b - 1 :: es.(a - 1)
  done;
  let trace = Array.make n None in
  let rec visit vs v =
    match trace.(v) with
    | Some us -> raise (Exit (drop (List.length us) (List.rev vs)))
    | None ->
        trace.(v) <- Some vs;
        List.iter (fun u -> visit (v :: vs) u) es.(v);
        trace.(v) <- None in
  try
    for v = 0 to n - 1 do
      visit [] v
    done;
    print_endline "-1"
  with Exit vs ->
    assert (List.length vs = List.length (List.sort_uniq compare vs));
    Printf.printf "%d\n" (List.length vs);
    List.iter (fun v -> Printf.printf "%d\n" @@ v + 1) vs
