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

def dig(entry, n, edges, visited)
  return (entry == n ? [] : nil) if visited[n]
  visited[n] = true
  res = nil
  edges[n].each{ |m|
    r = dig(entry, m, edges, visited)
    if r && (!res || res.size > r.size)
      res = r
    end
  }
  return res ? [n] + res : nil
end

res = nil
(1..N).each{ |i|
  r = dig(i, i, Edges, Array.new(N+1,false))
  if r && r.size >= 2 && (!res || res.size > r.size)
    res = r
  end
}
puts res ? [res.size,res] : -1
