//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int nmax = 1000;
vvint ad(nmax,vint(nmax));

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    vint cle(n,1);
    vint pn(n);
    vint cn(n);
    vvint par(n);
    vvint cld(n);
    REP(i,m){
        int a,b;
        cin >> a >> b;
        a--; b--;
        ad[a][b]=1;
        if(ad[b][a]==1){
            cout << 2 << endl;
            cout << a+1 << endl;
            cout << b+1 << endl;
            return 0;
        }
        par[b].pb(a);
        cld[a].pb(b);
        pn[b]++;
        cn[a]++;
    }
    queue<int> qp;
    int rmvd=0;
    REP(i,n){
        if(pn[i]==0)qp.push(i);
    }
    while(!qp.empty()){
        int now = qp.front();
        qp.pop();
        cle[now]=0;
        rmvd++;
        for(int i:cld[now]){
            pn[i]--;
            if(pn[i]==0)qp.push(i);
        }
    }
    if(rmvd==n){
        cout << "-1\n";
        return 0;
    }
    queue<int> qc;
    REP(i,n){
        if(cn[i]==0){
            qc.push(i);
        }
    }
    while(!qc.empty()){
        int now = qc.front();
        qc.pop();
        cle[now]=0;
        rmvd++;
        for(int i:par[now]){
            cn[i]--;
            if(cn[i]==0)qc.push(i);
        }
    }
    

    
    queue<int> q;

    int s=-1;
    vint ans(n,-1);
    REP(i,n){
        if(cle[i]==1&&s==-1){
            s=i;
            q.push(i);
        }
    }
    int cnt=0;
    vint vstd(n,0);
    vint cyc(n,-1);
    while(!q.empty()){
        int now=q.front();
        ans[cnt]=now;
        cnt++;
        q.pop();
        vstd[now]=1;
        for(int i:cld[now]){
            if(cle[i]==0)continue;
            if(vstd[i]==0){
                q.push(i); 
                break;
            }
        }
    }
    
    queue<int> q2;
    q2.push(0);
    REP(x,n){
        int ni = q2.front();
        q2.pop();
        int now=ans[ni];
        int next;
        REP(i,n-1){
            int t=(ni+i+1)%n;
            if(ans[t]>=0){
                if(ad[now][ans[t]]==1){
                    next=t;
                }
            }
        }
        q2.push(next);
        if(next<ni){
            next+=n;
        }
        for(int i=ni+1;i<next;i++){
            ans[i%n]=-1;
        }
    }
    int c=0;
    REP(i,n){
        if(ans[i]>=0)c++;
       }
    cout << c << endl;
    REP(i,n){
        if(ans[i]>=0){
            cout << ans[i]+1 << endl;
        }
    }



    return 0;
}

Measured memory_bytes: 4352