### BUGGY CODE ###

N, M = [int(x) for x in input().strip().split(" ")]

def dfs(v):
    pvs = set([v])
    path = [v]
    def _dfs(v, path):
        for u in d[v]:
            if u in pvs:
                for i, c in enumerate(path):
                    if c == u:
                        break
                return path[i+1:]  + [u]
            if u in vs:
                continue
            pvs.add(u)
            vs.add(u)
            loop = _dfs(u, path + [u])
            pvs.remove(u)
            if loop:
                return loop
        return False
    return _dfs(v, path)

def dfs_w(v):
    # dfs while版 
    pvs = set([v])
    nvs = [v]
    path = [v]
    while True:
        if len(nvs) == 0:
            break
        v = nvs.pop()
        if v < 0:
            pvs.remove(path[-1])
            path.pop()
        else:
            path.append(v)
            pvs.add(v)
            vs.add(v)
            for u in d[v]:
                if u in pvs:
                    for i, c in enumerate(path):
                        if c == u:
                            break
                    return path[i+1:]  + [u]
                if u in vs:
                    continue
                nvs += [-v, u]
    return False

d = [set() for _ in range(N+1)]
for _ in range(M):
    a, b = [int(x) for x in input().strip().split(" ")]
    d[a].add(b)

vs = set()
for i in range(N):
    i += 1
    if i in vs:
        continue
    vs.add(i)
    loop = dfs_w(i)
    if loop:
        break

if not loop:
    print(-1)
    import sys
    sys.exit()
v2i = [-1 for _ in range(N+1)]
for i, v in enumerate(loop):
    v2i[v] = i

nloop, pvs = [], set()
v = loop[0]
f = False
while True:
    nloop.append(v)
    pvs.add(v)
    max_i = -1
    for u in d[v]:
        if u in pvs:
            f = True
            nloop.append(u)
            break
        if v2i[v] > v2i[u]:
            continue
        max_i = max(v2i[u], max_i)
    if f:
        break
    v = loop[max_i]

for i, x in enumerate(nloop):
    if x == nloop[-1]:
        break
nloop = nloop[i+1:]
print(len(nloop))
for v in nloop:
    print(v)


### FIXED CODE ###


N, M = [int(x) for x in input().strip().split(" ")]

def dfs(v, l):
    for u in d[v]:
        if u in pvs:
            return l + [u]
        if u in vs:
            continue
        pvs.add(u)
        vs.add(u)
        ll = dfs(u, l + [u])
        pvs.remove(u)
        if ll:
            return ll
    return False

d = [set() for _ in range(N)]
for _ in range(M):
    a, b = [int(x) for x in input().strip().split(" ")]
    d[a-1].add(b-1)

vs = set()
for i in range(N):
    if i in vs:
        continue
    vs.add(i)
    pvs = set([i])
    loop = dfs(i, [i])
#    print(i, loop, vs)
    if loop:
        break

import sys
#print(loop)
if not loop:
    print("-1")
    sys.exit()
else:
    ll = []
    lx = loop[-1]
    f = False
    for x in loop:
        if lx == x and not f:
            f = True
            continue
        if not f:
            continue
        ll.append(x)
    loop = ll

v2i = [-1 for _ in range(N)]
for i, v in enumerate(loop):
    v2i[v] = i

i = 0
vs = set()
ss = set()
lnum = len(loop)
ll = []
while True:
    v = loop[i]
    if i in vs:
        f = False
        loop = []
        for x in ll:
            if v == x:
                f = True
            if f:
                loop.append(x)
        break

    m = 0
#    print(v, d[v], v2i, ss, vs)
    for u in d[v]:
        if v2i[u] == -1:
            continue
        if v2i[u] in ss:
            continue
        if v2i[v] > v2i[u]:
            m = max(lnum - v2i[v] + v2i[u], m)
        else:
            m = max(v2i[u] - v2i[v], m)
#        print(u, m, v2i[u])
    for j in range(m-1):
        ss.add((i + j + 1) % lnum)
    vs.add(i)
    ll.append(v)
#    print(i, m, loop)
    i = (i + m) % lnum
#    print(i)

print(len(loop))
for i in loop:
    print(i+1)