import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue = BinaryHeap!(Array!long, "a<b");
// dfmt on

void main()
{
    long N, M;
    scan(N, M);
    auto G = new long[][](N);
    auto G_rev = new long[][](N);
    foreach (i; 0 .. M)
    {
        long A, B;
        scan(A, B);
        A--, B--;
        G[A] ~= B;
        G_rev[B] ~= A;
    }
    long[] dfs()
    {
        long[][] results;
        foreach (s; 0 .. N)
        {
            DList!long stack;
            auto dist = new long[](N);
            auto from = new long[](N);
            dist[] = long.max;
            from[s] = s;
            stack.insertBack(s);
            dist[s] = 0;
            long mindist = long.max;
            long minlast = -1;
            while (!stack.empty)
            {
                long v = stack.back;
                stack.removeBack();
                foreach (w; G[v])
                    if (w == s)
                    {
                        if (dist[v] + 1 < mindist)
                        {
                            mindist = dist[v] + 1;
                            minlast = v;
                        }
                    }
                    else if (dist[v] + 1 < dist[w])
                    {
                        dist[w] = dist[v] + 1;
                        from[w] = v;
                        stack.insertBack(w);
                    }
            }
            if (minlast != -1)
            {
                DList!long result;
                long v = minlast;
                while (from[v] != v)
                {
                    result.insertFront(v);
                    v = from[v];
                }
                result.insertFront(s);
                results ~= result.array;
            }
        }
        if (results.empty)
            return [];
        long m = 0;
        long ml = results[0].length;
        foreach (i; 0 .. results.length)
            if (results[i].length < ml)
            {
                m = i;
                ml = results[i].length;
            }
        return results[m];
    }

    auto loop = dfs();
    if (loop.empty)
    {
        writeln(-1);
        return;
    }
    writeln(loop.length);
    foreach (v; loop)
        writeln(v + 1);
}
