N,M = gets.split.map &:to_i
Edges = (0..N).map{ [] }
M.times{
  a,b = gets.split.map &:to_i
  Edges[a].push(b)
}

Visited = Array.new(N+1,false)

def dig(n, edges, visited)
  return nil if edges[n].size == 0
  return [] if visited[n]
  visited[n] = true
  edges[n].each{ |m|
    r = dig(m, edges, visited)
    if r
      return [n] + r
    end
  }
  return nil
end

(1..N).each{ |i|
  r = dig(i, Edges, Visited)
  if r && r.size >= 2
    puts r.size, r; exit
  end
}
p -1
