import sys

N,M=list(map(int,input().split()))

d=[set()for _ in range(N+1)]

def f(v,h,q):

 if d[v]&q:

  l=[]

  for x in h[::-1]:

   l=[x]+l

   if x in d[v]:break

  L=[]

  while v!=x:

   for y in l:

    if v in d[y]:

     L=[v]+L

     v=y

     break

  print(("\n".join(str(x)for x in[len(L)+1,x]+L[::-1])));sys.exit()

 for u in d[v]:f(u,h+[u],q|{u})

for _ in range(M):a,b=list(map(int,input().split()));d[a].add(b)

v=0;exec("v+=1;f(v,[v],{v});"*N)

print((-1))
import sys

N,M=list(map(int,input().split()))

d=[set()for _ in range(N+1)]

def f(v,h,q):

 if d[v]&q:

  l=[]

  for x in h:

   l=[x]+l

   if x in d[v]:break

  L=[]

  while v!=x:

   for y in l:

    if v in d[y]:

     L=[v]+L

     v=y

     break

  print(("\n".join(str(x)for x in[len(L)+1,x]+L)));sys.exit()

 for u in d[v]:f(u,[u]+h,q|{u})

for _ in range(M):a,b=list(map(int,input().split()));d[a].add(b)

v=0;exec("v+=1;f(v,[v],{v});"*N)

print((-1))
import sys

N, M = list(map(int, input().split()))
d = [set() for _ in range(N + 1)]


def f(v, h, q):
    if d[v] & q:
        l = []
        for x in h[::-1]:
            l = [x] + l
            if x in d[v]:
                break
        L = []
        while v != x:
            for y in l:
                if v in d[y]:
                    L = [v] + L
                    v = y
                    break
        print(("\n".join(str(x) for x in [len(L) + 1, x] + L[::-1])))
        sys.exit()
    for u in d[v]:
        f(u, h + [u], q | {u})


for _ in range(M):
    a, b = list(map(int, input().split()))
    d[a].add(b)
v = 0
exec("v+=1;f(v,[v],{v});" * N)
print((-1))

import sys

N, M = list(map(int, input().split()))
d = [set() for _ in range(N + 1)]


def f(v, h, q):
    if d[v] & q:
        l = []
        for x in h:
            l = [x] + l
            if x in d[v]:
                break
        L = []
        while v != x:
            for y in l:
                if v in d[y]:
                    L = [v] + L
                    v = y
                    break
        print(("\n".join(str(x) for x in [len(L) + 1, x] + L)))
        sys.exit()
    for u in d[v]:
        f(u, [u] + h, q | {u})


for _ in range(M):
    a, b = list(map(int, input().split()))
    d[a].add(b)
v = 0
exec("v+=1;f(v,[v],{v});" * N)
print((-1))

-        for x in h[::-1]: +        for x in h: -        print(("\n".join(str(x) for x in [len(L) + 1, x] + L[::-1]))) +        print(("\n".join(str(x) for x in [len(L) + 1, x] + L))) -        f(u, h + [u], q | {u}) +        f(u, [u] + h, q | {u})