
import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main()
{
    int n, m;
    readf("%s %s", &n, &m);
    readln;

    auto g = new int[][] (n+1);
    
    foreach (_; 0 .. m) {
        int u, v;
        readf("%s %s", &u, &v);
        readln;
        
        g[u] ~= v;
    }
    
    auto clr = new int[] (n+1);
    clr[] = 0;
    
    auto ans = make!(DList!int);
    
    int go(int v) { 
        clr[v] = 1;
        ans ~= v;
        
        foreach_reverse (u; g[v]) {
            if (clr[u] == 1) {
                return u;
            }
        } 
        
        foreach (u; g[v]) {
            if (clr[u] == 2) { continue; }
            
            int x = go(u);
            if (x > 0) { return x; }
        }
        
        clr[v] = 2;
        ans.removeBack();
        
        return 0;
    }
    
    foreach (i; 1 .. n+1) {
        if (clr[i] > 0) { continue; }
        
        int x = go(i);
        if (x > 0) {
            while (ans.front != x) { ans.removeFront(); } 
            
            int len = 0;
            foreach (_; ans) { ++len; }
            len.writeln;
            ans.each!writeln;
            
            return;
        }
    }
    
    writeln(-1);
}