
def dfs(to, history)
  if history.include?(to)
    target = history.slice(history.index(to), history.count - history.index(to))
    flag = true
    target.each do |i|
      unless (target - $ways[i]).count == target.count - 1
        flag = false
        break
      end
    end

    if flag
      puts target.count
      target.each do |i|
        puts i
      end
      exit
    else
      return
    end
  end

  $already << to
  next_history = history + [to]
  return if $ways[to].nil?
  $ways[to].each do |t|
    dfs(t, next_history)
  end
end

N, M = gets.split.map(&:to_i)
arrs = M.times.map { gets.split.map(&:to_i) }
$ways = arrs.group_by { |arr| arr[0] }.map { |k, v| [k, v.map { |vv| vv[1]}] }.to_h

$already = []

$ways.each do |from, to|
  $already = $already.uniq
  unless $already.include?(from)
    to.each do |t|
      $already << from
      dfs(t, [from])
    end
  end
end

puts '-1'