local mfl, mce = math.floor, math.ceil
local mmi, mma = math.min, math.max
local bls, brs = bit.lshift, bit.rshift
local SegTree = {}
SegTree.updateAll = function(self)
  for i = self.stagenum - 1, 1, -1 do
    local cnt = bls(1, i - 1)
    for j = 1, cnt do
      self.stage[i][j] = self.func(self.stage[i + 1][j * 2 - 1], self.stage[i + 1][j * 2])
    end
  end
end
SegTree.create = function(self, n, func, emptyvalue)
  self.func, self.emptyvalue = func, emptyvalue
  local stagenum, mul = 1, 1
  self.stage = {{}}
  while mul < n do
    mul, stagenum = mul * 2, stagenum + 1
    self.stage[stagenum] = {}
  end
  self.stagenum = stagenum
  for i = 1, n do self.stage[stagenum][i] = i end
  for i = n + 1, mul do self.stage[stagenum][i] = emptyvalue end
  self:updateAll()
end
SegTree.update = function(self, idx)
  for i = self.stagenum - 1, 1, -1 do
    local dst = brs(idx + 1, 1)
    local rem = dst * 4 - 1 - idx
    self.stage[i][dst] = self.func(self.stage[i + 1][idx], self.stage[i + 1][rem])
    idx = dst
  end
end
SegTree.top = function(self) return self.stage[1][1] end
SegTree.new = function(n, func, emptyvalue)
  local obj = {}
  setmetatable(obj, {__index = SegTree})
  obj:create(n, func, emptyvalue)
  return obj
end

local n, m = io.read("*n", "*n")
local len = {}
local edge = {}
local invedge = {}
local updated = {}
for i = 1, n + 1 do
  len[i] = {}
  for j = 1, n + 1 do
    len[i][j] = -1
  end
  edge[i] = {}
  invedge[i] = {}
  updated[i] = false
end
for i = 1, m do
  local a, b = io.read("*n", "*n")
  edge[a][b] = true
  invedge[b][a] = true
end
local g_start = false
local function getmin(a, b)
  if updated[a] and updated[b] then
    return len[g_start][a] < len[g_start][b] and a or b
  elseif updated[a] then return a
  elseif updated[b] then return b
  else return n + 1
  end
end
local st = SegTree.new(n, getmin, n + 1)
for i_start = 1, n do
  g_start = i_start
  for i = 1, n do
    len[i_start][i] = -1
    updated[i] = false
  end
  len[i_start][i_start] = 0
  updated[i_start] = true
  st:updateAll()
  while true do
    local src = st:top()
    if src == n + 1 then break end
    for dst, _u in pairs(edge[src]) do
      if len[i_start][dst] < 0 or len[i_start][src] + 1 < len[i_start][dst] then
        len[i_start][dst] = len[i_start][src] + 1
        updated[dst] = true
        st:update(dst)
      end
    end
    updated[src] = false
    st:update(src)
  end
end
local inf = 1000000007
local minlen = inf
local scand = 0
for i = 1, n do
  for j = 1, n do
    if i ~= j then
      if 0 <= len[i][j] and 0 <= len[j][i] then
        if len[i][j] + len[j][i] < minlen then
          minlen = len[i][j] + len[j][i]
          scand = i
        end
      end
    end
  end
end
if scand == 0 then
  print(-1)
else
  print(minlen)
  local ans = {scand}
  for i = minlen - 1, 1, -1 do
    local dst = ans[#ans]
    for src, _u in pairs(invedge[dst]) do
      if len[scand][src] == i and len[src][scand] == minlen - i then
        table.insert(ans, src)
        break
      end
    end
  end
  print(table.concat(ans, "\n"))
end
