#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MAX_V 1010
vector<int> G[MAX_V];
vector<int> rG[MAX_V];
vector<int> vs;
bool used[MAX_V];
int cmp[MAX_V];


void add_edge(int from, int to){
    G[from].push_back(to);
    rG[to].push_back(from);
}

void dfs(int v){
    used[v] = true;
    for(auto u: G[v]){
        if(!used[u]){
            dfs(u);
        }
    }
    vs.push_back(v);
}

void rdfs(int v, int k){
    used[v] = true;
    cmp[v] = k;
    for(auto u: rG[v]){
        if(!used[u]){
            rdfs(u, k);
        }
    }
}

int scc(int N){
    memset(used, 0, sizeof(used));
    vs.clear();

    for(int v = 0; v < N; v++) {
        if (!used[v]) {
            dfs(v);
        }
    }

    memset(used, 0, sizeof(used));
    int k = 0;
    for(int i = vs.size() - 1; i >= 0; i--){
        if(!used[vs[i]]){
            rdfs(vs[i], k++);
        }
    }
    return k;
}

ll d[MAX_V][MAX_V], d2[MAX_V][MAX_V];
int pre[MAX_V][MAX_V], pre2[MAX_V][MAX_V];

ll INF = 1e8+7;
void dijkstra1(int s, int N){
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d[s], d[s]+N, INF);
    d[s][s] = 0;
    que.push(P(0, s));

    while(!que.empty()){
        P p = que.top(); que.pop();
        int v = p.sc;
        if(d[s][v] < p.fs){
            continue;
        }
        for(auto e: G[v]){
            if(cmp[s] != cmp[e]){
                continue;
            }
            if(d[s][e] > d[s][v] + 1){
                d[s][e] = d[s][v] + 1;
                pre[s][e] = v;
                que.push(P(d[s][e], e));
            }
        }
    }
}

void dijkstra2(int s, int N){
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d2[s], d2[s]+N, INF);
    d2[s][s] = 0;
    que.push(P(0, s));

    while(!que.empty()){
        P p = que.top(); que.pop();
        int v = p.sc;
        if(d2[s][v] < p.fs){
            continue;
        }
        for(auto e: rG[v]){
            if(cmp[s] != cmp[e]){
                continue;
            }
            if(d2[s][e] > d2[s][v] + 1){
                d2[s][e] = d2[s][v] + 1;
                pre2[s][e] = v;
                que.push(P(d2[s][e], e));
            }
        }
    }
}


int main(){
    int N, M;
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int x, y;
        cin >> x >> y;
        x--; y--;
        add_edge(x, y);
    }

    int k = scc(N);
    if(k == N){
        cout << -1 << endl;
        return 0;
    }

    int count[1100];
    fill(count, count+1100, 0);
    for(int i = 0; i < N; i++){
        count[cmp[i]]++;
    }

    int tk = 0, mink = INF;
    for(int i = 0; i < N; i++){
        if(count[cmp[i]] > 1 && count[cmp[i]] < mink) {
            tk = cmp[i];
            mink = count[cmp[i]];
        }
    }

    ll minDis = INF;
    int dis1 = 0, dis2 = 0;
    for(int i = 0; i < N; i++){
        if(cmp[i] != tk){
            continue;
        }
        dijkstra1(i, N);
        dijkstra2(i, N);
        for(int j = 0; j < N; j++) {
            if (cmp[i] != tk || j == i) {
                continue;
            }
            if (d[i][j] + d2[i][j] < minDis) {
                dis1 = i; dis2 = j;
                minDis = d[i][j] + d2[i][j];
            }
        }
    }

    vector<int> res;
    res.push_back(dis1);
    int dis3 = pre2[dis1][dis2];
    while(dis2 != dis1){
        res.push_back(dis2);
        dis2 = pre[dis1][dis2];
    }
    while(dis3 != dis1){
        res.push_back(dis3);
        dis3 = pre2[dis1][dis3];
    }

    cout << res.size() << endl;
    for(auto v: res){
        cout << v + 1 << endl;
    }



    return 0;
}


Measured memory_bytes: 24192