import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

bool[] seen, finished;
int pos = -1;
int[] hist;

void dfs(int[][] adj, int v) {
    seen[v] = true;
    hist ~= v;
    foreach (nv ; adj[v]) {
        if (finished[nv]) continue;

        if (seen[nv] && !finished[nv]) {
            pos = nv;
            return;
        }

        dfs(adj, nv);

        if (pos != -1) return;
    }

    hist.popBack();
    finished[v] = true;
}

void main() {
    int N, M;
    scan(N, M);
    auto adj = new int[][](N, 0);
    foreach (i ; 0 .. M) {
        int ai, bi;
        scan(ai, bi);
        ai--, bi--;
        adj[ai] ~= bi;
    }

    seen = new bool[](N);
    finished = new bool[](N);
    foreach (v ; 0 .. N) {
        dfs(adj, v);
        if (pos != -1) break;
    }

    if (pos == -1) {
        writeln(-1);
        return;
    }

    int[] cycle;
    while (!hist.empty) {
        int t = hist.back;
        cycle ~= t;
        hist.popBack();
        if (t == pos) break;
    }
    cycle.reverse();

    while (true) {
        auto ord = new int[](N);
        ord[] = -1;
        foreach (i ; 0 .. cycle.length) {
            ord[cycle[i]] = i.to!int;
        }
        int from = -1, to = -1;
        foreach (i ; 0 .. cycle.length) {
            foreach (nv ; adj[cycle[i]]) {
                if (nv != cycle[(i + 1) % cycle.length] && ord[nv] != -1) {
                    from = i.to!int;
                    to = ord[nv];
                    break;
                }
            }
            if (from != -1) break;
        }
        if (from == -1) break;

        int[] ncycle;
        ncycle ~= cycle[from];
        int i = to;
        while (i != from) {
            ncycle ~= cycle[i];
            i = (i + 1) % cycle.length.to!int;
        }
        cycle = ncycle;
    }

    writeln(cycle.length);
    cycle.each!(v => writeln(v + 1));
}






void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}
