lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

N = lines[0][0]
M = lines[0][1]

access = []
for i in 1..N do
  access[i-1] = []
end
for i in 1..M do
  from = lines[i][0]
  to = lines[i][1]
  access[from-1].push(to)
end

checked = []
num_checked = 0
for i in 1..N do
  checked[i-1] = false
end

boucle = false
while num_checked < N do
  visited = []
  path_to = []
  for i in 1..N do
    visited[i-1] = false
    path_to[i-1] = []
  end
  for i in 1..N do
    if checked[i-1] == false then
      target = [i]
      break
    end
  end
  while target != [] do
    next_target = []
    target.each do |i|
      visited[i-1] = true
      if checked[i-1] == false then
        checked[i-1] = true
        num_checked += 1
      end
      access[i-1].each do |j|
        path_to[i-1].each do |k|
          path_to[j-1].push(k)
        end
        path_to[j-1].push(i)
        next_target.push(j)
        if visited[j-1] then
          boucle = true
          puts path_to[j-1].length
          puts path_to[j-1]
          next_target = []
          num_checked = N
          break
        end
      end
      if boucle then
        break
      end
    end
    target = next_target
  end
end
    
if boucle == false then
  puts -1
end