import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

int[][1000] G;
int[1000] MEMO;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];
    foreach (_; 0..M) {
        auto ab = readln.split.to!(int[]);
        auto A = ab[0]-1;
        auto B = ab[1]-1;
        G[A] ~= B;
    }

    int[] walk(int i, int n) {
        int[] js;
        foreach (j; G[i]) if (MEMO[j] == n) js ~= j;
        if (js.length == 1) {
            return [js[0]+1, i+1];
        } else if (js.length > 1) {
            return [];
        }
        foreach (j; G[i]) {
            MEMO[j] = n;
            auto r = walk(j, n);
            if (!r.empty) return r ~= i+1;
            MEMO[j] = 0;
        }
        return [];
    }
    
    foreach (i; 0..N) {
        MEMO[i] = i+1;
        auto r = walk(i, i+1);
        if (!r.empty) {
            reverse(r);
            auto top = r[0];
            int[] rr = [top];
            foreach (p; r[1..$]) if (p != top) rr ~= p;
            writeln(rr.length);
            writeln(rr.to!(string[]).join(" "));
            return;
        }
    }
    writeln("-1");
}