STATUS = Array.new(1010, :unused)
def active?(v); STATUS[v] == :active; end
def activate!(v);  v.tap{ STATUS[v] = :active }; end
def inactivate!(v); v.tap{ STATUS[v] = :used }; end
def used?(v); STATUS[v] != :unused; end
def use!(v); v.tap{ STATUS[v] = :used }; end
def subgraph_include?(v); STATUS[v] == :unused; end
def subgraph_init!(vset); STATUS.fill(:used); vset.each{|v| STATUS[v] = :unused}; end

N,M = gets.split.map(&:to_i)
G = Array.new(N + 1){ [] }
E = M.times.map{ gets.split.map(&:to_i) }
E.each do |from,to|
  G[from] << to
end

def cycle_exists?
  (1 .. N).each do |s|
    next if used?(s)
    stack = [use!(s)]
    cycle = find_cycle(stack)
    return cycle if cycle
  end
  return false
end

def smaller_cycle?(cycle)
  subgraph_init!(cycle)
  
  shortcut = nil
  smaller_not_found = cycle.each_with_index.none? do |from, i|
    to = (i + 1 == cycle.size ? cycle[0] : cycle[i + 1])
    to_ = G[from].find{|t| subgraph_include?(t) && t != to }
    shortcut = [from, to_] if to_
  end
  
  return false if smaller_not_found

  stack = [activate!(shortcut[0]), use!(shortcut[1])]
  find_cycle(stack)
end

def find_cycle(stack)
  until stack.empty?
    u = stack.pop
    
    if active?(u) 
      inactivate!(u)
      next 
    end
    
    stack << activate!(u)
    
    G[u].each do |v|
      if active?(v)
        cycle = stack.select{|r| active?(r) }
                  .drop_while{|r| r != v } 
        return cycle
      end
      used?(v) || stack << use!(v)
    end
  end
  false
end

cycle = cycle_exists?

if !cycle
  puts -1
else
  loop do
    smaller = smaller_cycle?(cycle)
    break if !smaller  
    cycle = smaller
  end
  puts cycle.size
  puts cycle
end
