n, m = list(map(int, input().split()))

edges = [[] for _ in range(n)]

for _ in range(m):

    a, b = list(map(int, input().split()))

    edges[a - 1].append(b - 1)



ret = [0] * (n + 1)

for start in range(n):

    parent = [-1] * n

    q = [start]

    while len(q) > 0:

        i = q.pop(0)

        for j in edges[i]:

            if j == start:

                loop = [i]

                while i != start:

                    i = parent[i]

                    loop.append(i)

                if len(ret) > len(loop):

                    ret = loop

                break

            if parent[j] == -1:

                parent[j] = i

                q.append(j)



if len(ret) > n:

    print((-1))

else:

    print((len(ret)))

    for i in reversed(ret):

        print((i + 1))



n, m = list(map(int, input().split()))

edges = [[] for _ in range(n)]

for _ in range(m):

    a, b = list(map(int, input().split()))

    edges[a - 1].append(b - 1)



def dfs(index, visited, cycle):

    visited[index] = True

    cycle.append(index)

    for i in edges[index]:

        if visited.get(i):

            return cycle[cycle.index(i):]

        ret = dfs(i, visited, cycle)

        if ret:

            return ret

    visited[index] = False

    cycle.pop(-1)

    return None



def find_local_minimum(cycle):

    n = len(cycle)

    ind = {v: i for (i, v) in zip(list(range(n)), cycle)}

    ret = []

    i = 0

    while True:

        ret.append(i)

        nxt = 0

        for j in [ind[v] for v in edges[cycle[i]] if v in ind]:

            if j < i:

                j += n

            nxt = max(nxt, j)

        if nxt >= n:

            ret = ret[ret.index(nxt % n):]

            break

        i += 1

        while i < nxt:

            del ind[cycle[i]]

            i += 1

    return [cycle[i % n] for i in ret]



cycle = None

visited = {}

for start in range(n):

    if start not in visited:

        cycle = dfs(start, visited, [])

        if cycle:

            break



if cycle:

    ret = find_local_minimum(cycle)

    print((len(ret)))

    for i in ret:

        print((i + 1))

else:

    print((-1))



n, m = list(map(int, input().split()))
edges = [[] for _ in range(n)]
for _ in range(m):
    a, b = list(map(int, input().split()))
    edges[a - 1].append(b - 1)
ret = [0] * (n + 1)
for start in range(n):
    parent = [-1] * n
    q = [start]
    while len(q) > 0:
        i = q.pop(0)
        for j in edges[i]:
            if j == start:
                loop = [i]
                while i != start:
                    i = parent[i]
                    loop.append(i)
                if len(ret) > len(loop):
                    ret = loop
                break
            if parent[j] == -1:
                parent[j] = i
                q.append(j)
if len(ret) > n:
    print((-1))
else:
    print((len(ret)))
    for i in reversed(ret):
        print((i + 1))

n, m = list(map(int, input().split()))
edges = [[] for _ in range(n)]
for _ in range(m):
    a, b = list(map(int, input().split()))
    edges[a - 1].append(b - 1)


def dfs(index, visited, cycle):
    visited[index] = True
    cycle.append(index)
    for i in edges[index]:
        if visited.get(i):
            return cycle[cycle.index(i) :]
        ret = dfs(i, visited, cycle)
        if ret:
            return ret
    visited[index] = False
    cycle.pop(-1)
    return None


def find_local_minimum(cycle):
    n = len(cycle)
    ind = {v: i for (i, v) in zip(list(range(n)), cycle)}
    ret = []
    i = 0
    while True:
        ret.append(i)
        nxt = 0
        for j in [ind[v] for v in edges[cycle[i]] if v in ind]:
            if j < i:
                j += n
            nxt = max(nxt, j)
        if nxt >= n:
            ret = ret[ret.index(nxt % n) :]
            break
        i += 1
        while i < nxt:
            del ind[cycle[i]]
            i += 1
    return [cycle[i % n] for i in ret]


cycle = None
visited = {}
for start in range(n):
    if start not in visited:
        cycle = dfs(start, visited, [])
        if cycle:
            break
if cycle:
    ret = find_local_minimum(cycle)
    print((len(ret)))
    for i in ret:
        print((i + 1))
else:
    print((-1))

-ret = [0] * (n + 1) + + +def dfs(index, visited, cycle): +    visited[index] = True +    cycle.append(index) +    for i in edges[index]: +        if visited.get(i): +            return cycle[cycle.index(i) :] +        ret = dfs(i, visited, cycle) +        if ret: +            return ret +    visited[index] = False +    cycle.pop(-1) +    return None + + +def find_local_minimum(cycle): +    n = len(cycle) +    ind = {v: i for (i, v) in zip(list(range(n)), cycle)} +    ret = [] +    i = 0 +    while True: +        ret.append(i) +        nxt = 0 +        for j in [ind[v] for v in edges[cycle[i]] if v in ind]: +            if j < i: +                j += n +            nxt = max(nxt, j) +        if nxt >= n: +            ret = ret[ret.index(nxt % n) :] +            break +        i += 1 +        while i < nxt: +            del ind[cycle[i]] +            i += 1 +    return [cycle[i % n] for i in ret] + + +cycle = None +visited = {} -    parent = [-1] * n -    q = [start] -    while len(q) > 0: -        i = q.pop(0) -        for j in edges[i]: -            if j == start: -                loop = [i] -                while i != start: -                    i = parent[i] -                    loop.append(i) -                if len(ret) > len(loop): -                    ret = loop -                break -            if parent[j] == -1: -                parent[j] = i -                q.append(j) -if len(ret) > n: +    if start not in visited: +        cycle = dfs(start, visited, []) +        if cycle: +            break +if cycle: +    ret = find_local_minimum(cycle) +    print((len(ret))) +    for i in ret: +        print((i + 1)) +else: -else: -    print((len(ret))) -    for i in reversed(ret): -        print((i + 1))