#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define li          long
#define ll          long long
#define ull         unsigned long long
#define ff          first
#define ss          second
#define pii         pair<int,int>
#define pli         pair<li,li>
#define pll         pair<ll,ll>
#define pb          push_back
#define fo(i,k,n)   for(int i = k;i<n; i++)
#define ro(i,k,n)   for(int i = k; i>=n; i--)
#define fd(i,k,n,d) for(int i = k; i<n; i+=d)
#define tc          int t;cin>>t;while(t--)
#define all(v)      v.begin(),v.end()
#define inf         INT_MAX
#define ninf        INT_MIN
#define W(x)        cout<<x<<endl
#define WW(x,y)     cout<<x<<' '<<y<<endl;
#define in(x)       cin>>x
#define v(x)        vector<x>
#define int         long long
#define ar(x,y)       array<x,y>
const ll mod1 = 99844353;
const ll mod2 = 1e9+7;
template <class T>
using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

//****************************************************************************************************************************************//

void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

//*****************************************************************************************************************************************//

template<class T>
T power(T a,T b){
    T res = (T)1;
    while(b>0){
        if(b&1)res = res*a;
        b>>=1;
        a*=a;
    }
    return res;
}

template<class T>
T power(T a,T b,T m){
    T res = (T)1;
    a%=m;
    while(b>0){
        if(b&1)res = (res*a)%m;
        b>>=1;
        a = (a*a)%m;
    }
    return res;
}

//*****************************************************************************************************************************************//

struct dsu{
  map<int,int> pr,sz;
  dsu(){
    (this->pr).clear();
    (this->sz).clear();
  }
  void make(int x){
    pr[x] = x;
    sz[x] = 1;
  }
  int getpar(int x){
    if(pr[x] == x)return x;
    return pr[x] = getpar(pr[x]);
  }
  void merge(int x,int y){
    x = getpar(x);
    y = getpar(y);
    if(sz[x]<sz[y])swap(x,y);
    pr[y] = x;
    sz[x]+=sz[y];
    sz[y] = 0;
  }
};

//******************************************************************************************************************************************//

const int mxn = 1001;
set<int> adj[mxn];
int n,m,a,b;
v(bool) vis(mxn);
vector<int> ans;
vector<int> stck(mxn);

bool dfs(int s,int pr){
    vis[s] = true;
    stck[s] = 1;
    for(int v:adj[s]){
        if(stck[v] == 1){
            int start = v,end = s;
            map<int,int> track;
            v(int)dist(mxn,INT_MAX);
            dist[start] = 0;
            set<ar(int,2)> st;
            st.insert({start,0});
            track[start] = -1;
            while(!st.empty()){
                ar(int,2) p = *st.begin();
                st.erase(st.begin());
                int curr_node = p[0],curr_dist = p[1];
                dist[curr_node] = curr_dist;
                if(curr_node == end)break;
                for(int v:adj[curr_node]){
                    if(dist[v]>curr_dist+1){
                        if(st.count({v,dist[v]}))st.erase({v,dist[v]});
                        dist[v] = curr_dist+1;
                        track[v] = curr_node;
                        st.insert({v,dist[v]});
                    }
                }
            }
            int node = end;
            while(track[node]!=-1){
                ans.pb(node);
                node = track[node];
            }
            ans.pb(node);
            return true;
        }
        if(!vis[v] && !stck[v] &&dfs(v,s))return true;
    }
    stck[s] = 0;
    return false;
}

void solve(){
    cin>>n>>m;
    for(int i = 1; i<=n; i++){
        adj[i].clear();
        vis[i] = false;
        stck[i] = 0;
    }
    for(int i = 0; i<m; i++){
        cin>>a>>b;
        adj[a].insert(b);
    }
    ans.clear();
    bool ok = 0;
    for(int i = 1; i<=n; i++){
        if(!vis[i]&&dfs(i,-1)){
            ok = 1;
            break;
        }
    }
    if(ok){
        reverse(all(ans));
        unordered_map<int,int> mp;
        int start = 0,end = ans.size()-1;
        for(int i = 0; i<ans.size(); i++){
            for(auto x: adj[ans[i]]){
                if(mp.find(x)!=mp.end()){
                    start = max(start,mp[x]);
                    end = min(end,i);
                }
            }
            mp[ans[i]] = i;
        }
        cout<<end-start+1<<"\n";
        for(int i = start; i<=end; i++)cout<<ans[i]<<"\n";
    }
    else cout<<-1<<"\n";
}

signed main(){
    fastio();
    int cs = 1;
    //cin>>cs;
    while(cs--){
        solve();
    }
}


Measured memory_bytes: 4112