module IntSet = Set.Make (struct
  type t = int
  let compare = compare
end)

let rec solve es vs (start, xs) (goal, ys) =
  if IntSet.subset (es start) vs then
    if IntSet.subset (es goal) vs then
      start :: xs @ List.rev (goal :: ys)
    else begin
      let goal' = IntSet.choose (IntSet.diff (es goal) vs) in
      solve es (IntSet.add goal' vs) (start, xs) (goal', goal :: ys)
    end
  else begin
    let start' = IntSet.choose (IntSet.diff (es start) vs) in
    solve es (IntSet.add start' vs) (start', start :: xs) (goal, ys)
  end

let () =
  let n, m = Scanf.scanf "%d %d\n" (fun n m -> n, m) in
  let abs = Array.init m (fun _ -> Scanf.scanf "%d %d\n" (fun a b -> a, b)) in
  let es =
    let es = Array.make n IntSet.empty in
    Array.iter (fun (a, b) ->
      es.(a - 1) <- IntSet.add b es.(a - 1);
      es.(b - 1) <- IntSet.add a es.(b - 1)) abs;
    fun i -> es.(i - 1) in
  let (start, goal) = abs.(0) in
  solve es (IntSet.add start (IntSet.singleton goal)) (start, []) (goal, [])
  |> (fun xs ->
      Printf.printf "%d\n" (List.length xs);
      List.iter (Printf.printf "%d ") xs;
      print_newline ())