#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

struct TopologicalSort{
    vector<vector<int>> E;
    vector<int> hist;
    int st = -1;
    TopologicalSort(vector<vector<int>> g){ E = g;}
    void add_edge(int a, int b) {E[a].push_back(b);}
    bool visit(int v, vector<int> &order, vector<int> &color){
        color[v] = 1;
        hist.eb(v);
        for(int u : E[v]){
            if(color[u] == 2) continue;
            if(color[u] == 1) {
                st = u;
                return false;
            }

            if(!visit(u,order,color)) return false;
        }
        hist.pop_back();
        order.push_back(v);
        color[v] = 2;
        return true;
    }
    bool sort(vector<int> &order){
        int n = E.size();
        vector<int> color(n);
        for(int u = 0; u < n; u++){
            if(!color[u] && !visit(u,order,color)) return false;
        }
        reverse(order.begin(),order.end());
        return true;
    }
};

VVI g;
VI used;
int st = -1;
VI loop;
const int MAX_N = 1010;
int N,M;

//void dfs(int v, VI& route){
//    //dump(v)
//    //for(int x : route){
//    //    cout << x <<" ";
//    //}
//    //cout << endl;
//    for(int u : g[v]){
//        if(u == st){
//            loop = route; 
//            return;
//        }
//        if(used[u]) continue;
//        used[u] = 1;
//        route.eb(u);
//        dfs(u,route);
//        used[u] = 0; 
//        route.pop_back();
//    }
//}

bool check(VI loop){
        int tg[MAX_N];
        VI ex(MAX_N);
        REP(i,MAX_N){
            tg[i] = -1;
        }
        int sz = SZ(loop);
        REP(i,sz){
            ex[loop[i]] = 1;
            tg[loop[i]] = loop[(i+1)%sz];
        }
        int h1 = -1, h2 = -1;

        REP(i,N){
            for(int x : g[i]){
                if(ex[i] == 1 && ex[x] == 1){
                    if(tg[i] != x){
                        h1 = i;
                        h2 = x;
                    }
                }

            }
        }
        dump(h1)
            dump(h2)
        if(h1 == -1 && h2 == -1){
            return true;
        }else{
            return false;
        }
}

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    cin >> N >> M;
    g.resize(N);
    used.resize(N);
    REP(i,M){
        int a,b; cin >> a >> b;
        a--; b--;
        g[a].eb(b);
    }
    TopologicalSort tps(g);
    VI trash;
    bool dag = tps.sort(trash);
    if(dag){
        cout << -1 << endl;
        return 0;
    }
    st = tps.st;
    VI hist = tps.hist;

    while(!hist.empty()){
        int t = hist.back();
        loop.eb(t);
        hist.pop_back();
        if(t == st) break;
    }
    reverse(loop.begin(),loop.end());

    //dfs(st, route);
    //for(int x : loop){
    //    cout << x << " ";
    //}
    //cout << endl;
    //

    while(!check(loop)){
        int tg[MAX_N];
        VI ex(N);
        REP(i,MAX_N){
            tg[i] = -1;
        }
        int sz = SZ(loop);
        REP(i,sz){
            ex[loop[i]] = 1;
            tg[loop[i]] = loop[(i+1)%sz];
        }

        //for(int x : loop){
        //    cout << x << " ";
        //}
        //cout << endl;
    

        //REP(i,N){
        //    cout << tg[i] << " ";
        //}
        //cout << endl;
        int h1 = -1, h2 = -1;

        REP(i,N){
            for(int x : g[i]){
                if(ex[i] == 1 && ex[x] == 1){
                    if(tg[i] != x){
                        h1 = i;
                        h2 = x;
                    }
                }

            }
        }
        dump(h1)
        dump(h2)
        VI newloop = {h1,h2};
        int now = h2;
        while(tg[now] != h1){
            now = tg[now];
            newloop.eb(now);
        }
        loop = newloop;

    }
    cout << SZ(loop) << endl;
    for(int x : loop){
        cout << x+1 << endl;
    }
}

Measured memory_bytes: 512