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;

int[] dist, prev;

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;
    }

    int min_c = inf;
    int start = -1;

    foreach (v ; 0 .. N) {
        bfs(adj, v);
        if (dist[v] < min_c) {
            min_c = dist[v];
            start = v;
        }
    }

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

    bfs(adj, start);

    debug {
        writeln(start);
        writeln(dist);
        writeln(prev);
    }

    int[] cyc = [start];
    auto pos = prev[start];

    while (pos != start) {
        cyc ~= pos;
        pos = prev[pos];
    }

    writeln(cyc.length);
    cyc.each!(c => writeln(c + 1));
}

void bfs(int[][] adj, int s) {
    auto N = adj.length.to!int;
    dist = new int[](N);
    prev = new int[](N);

    dist[] = inf;
    prev[] = -1;
    auto q = Queue!(int)(N);

    foreach (u ; adj[s]) {
        dist[u] = 1;
        q.insert(u);
        prev[u] = s;
    }


    while (!q.empty) {
        auto v = q.front;
        q.popFront();

        foreach (u ; adj[v]) {
            if (dist[u] == inf) {
                dist[u] = dist[v] + 1;
                prev[u] = v;
                q.insert(u);
            }
        }
    }

    return;
}

struct Queue(T) {
    private {
        size_t cap, head, tail;
        T[] data;
    }

    this (size_t n) in {
        assert(n > 0, "The capacity of a queue must be a positive integer.");
    } body {
        cap = n + 1;
        data = new T[](cap);
    }

    void clear() {
        head = tail = 0;
    }

    bool empty() {
        return head == tail;
    }

    bool full() {
        return head == (tail + 1) % cap;
    }

    size_t length() {
        return head <= tail ? tail - head : cap - head + tail;
    }

    T front() in {
        assert(!empty, "The queue is empty.");
    } body {
        return data[head];
    }

    void removeFront() in {
        assert(!empty, "The queue is empty.");
    } body {
        (++head) %= cap;
    }

    alias popFront = removeFront;

    void insertBack(T x) in {
        assert(!full, "The queue is full.");
    } body {
        data[tail++] = x;
        tail %= cap;
    }

    alias insert = insertBack;

    T[] array() {
        return head <= tail ? data[head .. tail].dup : data[head .. $] ~ data[0 .. tail];
    }

    string toString() {
        import std.format : format;

        if (head <= tail) {
            return format("[%(%s, %)]", data[head .. tail]);
        }
        else {
            return format("[%(%s, %)", data[head .. $]) ~ format(", %(%s, %)]", data[0 .. tail]);
        }
    }
}




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;
}
