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.getRange = function(self, left, right)
  if left == right then return self.stage[self.stagenum][left] end
  local stagenum = self.stagenum
  local ret = self.emptyvalue
  while left <= right do
    local stage, sz = 1, bls(1, stagenum - 1)
    local len = right - left + 1
    while (left - 1) % sz ~= 0 or len < sz do
      stage, sz = stage + 1, brs(sz, 1)
    end
    ret = self.func(ret, self.stage[stage][1 + brs(left - 1, stagenum - stage)])
    left = left + sz
  end
  return ret
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 longest_len = {}
local edge = {}
local invedge = {}
local updated = {}
local startcand = {}
for i = 1, n + 1 do
  longest_len[i] = -1
  edge[i] = {}
  invedge[i] = {}
  updated[i] = false
  startcand[i] = true
end
for i = 1, m do
  local a, b = io.read("*n", "*n")
  edge[a][b] = true
  invedge[b][a] = true
  startcand[b] = false
end
local function getmax(a, b)
  if updated[a] and updated[b] then
    return longest_len[a] < longest_len[b] and b or a
  elseif updated[a] then return a
  elseif updated[b] then return b
  else return n + 1
  end
end
-- find loop candidate
local st = SegTree.new(n, getmax, n + 1)
for i = 1, n do
  longest_len[i] = 0
  updated[i] = true
end
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 longest_len[dst] < 0 or longest_len[dst] < longest_len[src] + 1 then
      if longest_len[dst] < n then
        longest_len[dst] = longest_len[src] + 1
        updated[dst] = true
        st:update(dst)
      end
    end
  end
  updated[src] = false
  st:update(src)
end

local loopCandidates = {}
for i = 1, n do
  if n <= longest_len[i] then
    loopCandidates[i] = true
  end
end
-- remove no-loop points from loop candidate points
while true do
  local removed = false
  for src, _u in pairs(loopCandidates) do
    local f = false
    for dst, _u2 in pairs(edge[src]) do
      if loopCandidates[dst] then
        f = true
        break
      end
    end
    if not f then loopCandidates[src], removed = nil, true break end
  end
  if not removed then break end
end

-- remove all no-loop edges
for src, _u in pairs(loopCandidates) do
  for dst, _u2 in pairs(edge[src]) do
    if not loopCandidates[dst] then edge[src][dst] = nil end
  end
  for dst, _u2 in pairs(invedge[src]) do
    if not loopCandidates[dst] then invedge[src][dst] = nil end
  end
end
for i = 1, n do
  if not loopCandidates[i] then
    edge[i] = {}
    invedge[i] = {}
  end
end

-- find first length and second length from certain point
local loop_len = {}
local loop_started = {}
for src, _u in pairs(loopCandidates) do
  loop_len[src] = {-1, -1}
  loop_started[src] = false
end
if next(loopCandidates) then
  local src = next(loopCandidates)
  loop_len[src][1] = 0
  updated[src] = true
end

local function getlooptask(a, b)
  if updated[a] and updated[b] then
    if loop_len[a][2] < 0 and loop_len[b][2] < 0 then
      return loop_len[a][1] < loop_len[b][1] and a or b
    elseif loop_len[a][2] < 0 then return a
    elseif loop_len[b][2] < 0 then return b
    else
      return loop_len[a][2] < loop_len[b][2] and a or b
    end
  elseif updated[a] then return a
  elseif updated[b] then return b
  else return n + 1
  end
end

st.func = getlooptask
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 loop_started[dst] then
      if loop_started[src] then
        if loop_len[dst][2] < 0 or loop_len[src][2] + 1 < loop_len[dst][2] then
          loop_len[dst][2] = loop_len[src][2] + 1
          updated[dst] = true
          st:update(dst)
        end
      else
        if loop_len[dst][2] < 0 or loop_len[src][1] + 1 < loop_len[dst][2] then
          loop_len[dst][2] = loop_len[src][1] + 1
          updated[dst] = true
          st:update(dst)
        end
      end
    else
      if loop_len[dst][1] < 0 or loop_len[src][1] + 1 < loop_len[dst][1] then
        loop_len[dst][1] = loop_len[src][1] + 1
        updated[dst] = true
        st:update(dst)
      end
    end
  end
  loop_started[src] = true
  updated[src] = false
  st:update(src)
end

-- get start of shortest loop
local short_loop_start = false
local short_loop_len = false
local short_loop_v1 = false
local short_loop_v2 = false
for src, v in pairs(loop_len) do
  local len = v[2] - v[1]
  if 0 < len then
    local f = false
    if not short_loop_len or len < short_loop_len then
      f = true
    elseif short_loop_len == len then
      if v[1] < short_loop_v1 then
        f = true
      end
    end
    if f then
      short_loop_start, short_loop_len = src, len
      short_loop_v1, short_loop_v2 = v[1], v[2]
    end
  end
end

-- recalculate length
local shortest_len = {}
for i = 1, n do
  shortest_len[i] = -1
  updated[i] = false
end
local function getmin(a, b)
  if updated[a] and updated[b] then
    return shortest_len[a] < shortest_len[b] and a or b
  elseif updated[a] then return a
  elseif updated[b] then return b
  else return n + 1
  end
end

if short_loop_start then
  shortest_len[short_loop_start] = 0
  updated[short_loop_start] = true
  st.func = getmin
  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 shortest_len[dst] < 0 or shortest_len[src] + 1 < shortest_len[dst] then
        shortest_len[dst] = shortest_len[src] + 1
        updated[dst] = true
        st:update(dst)
      end
    end
    updated[src] = false
    st:update(src)
  end
  -- restore path
  local ans = {short_loop_start}
  for i = short_loop_len - 1, 1, -1 do
    local dst = ans[#ans]
    for src, _u in pairs(invedge[dst]) do
      if shortest_len[src] == i then
        table.insert(ans, src)
        break
      end
    end
  end
  print(short_loop_len)
  print(table.concat(ans, "\n"))
else
  print(-1)
end
