#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


// 有向グラフでの閉路検出
// O(V+E)
struct AcyclicCheck {
    int NMAX;
    vector<int> status;
    // 0:New, 1:Active, 2:Finished
    // Activeは行きがけ順序、Finishedは帰り掛け順序
    vector<vector<int>> const * g;

    AcyclicCheck(int NMAX, vector<vector<int>> const & G) :NMAX(NMAX) {
        status.resize(NMAX, 0);
        g = &G;
    }
    
    bool isAcyclicDFS(int v) {
        status[v] = 1;
        for(auto to : (*g)[v]) {
            if(status[to] == 1) return false;
            else if(status[to] == 0) {
                if(!isAcyclicDFS(to)) return false;
            }
        }
        status[v] = 2;
        return true;
    }

    bool isAcyclic() {
        rep(i, NMAX) status[i] = 0;
        rep(i, NMAX) if(status[i] == 0) {
            if(!isAcyclicDFS(i)) return false;
        }
        return true;
    }
};

vector<int> bfs(vector<vector<int>> const & G, int N, int s){
    int const inf = 1<<29;
    vector<int> dist(N, inf), pre(N, -1);
    
    queue<int> q;
    dist[s] = 0;
    q.push(s);

    while(!q.empty()){
        int now = q.front(); q.pop();
        for(auto to : G[now]){
            if(dist[to] > dist[now]+1) {
                dist[to] = dist[now]+1;
                pre[to] = now;
                q.push(to);
            }
        }
    }

    pair<int, int> best(inf, -1);
    rep(i, N){
        if(i == s) continue;
        for(auto j : G[i]) {
            if(j == s) {
                chmin(best, make_pair(dist[i], i));
            }
        }
    }

    if(best.first == inf){
        return vector<int>(N+1, 0);
        // return a{N+1, 0} でダメだった。なんで？
    }
    else{
        vector<int> ans;
        int now = best.second;
        while(now != -1){
            ans.push_back(now);
            now = pre[now];
        }
        return ans;
    }
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N, M; cin >> N >> M;
    vector<vector<int>> G(N);
    rep(i, M){
        int a, b; cin >> a >> b;
        --a; --b;
        G[a].push_back(b);
    }

    AcyclicCheck ac(N, G);
    if(ac.isAcyclic()) { cout << -1 << endl; return 0; }

    vector<int> ans(N+1, 0);
    rep(i, N) {
        auto now = bfs(G, N, i);
        if(now.size() < ans.size()) ans = now;
    }

    cout << ans.size() << endl;
    for(int v : ans) cout << v+1 << endl;

    return 0;
}

Measured memory_bytes: 384