/// However long the night,
///     The dawn will break
/// ICPC next year

#include<bits/stdc++.h>
using namespace std ;
const int N = 1e3+5 ;
int n ,m ,a ,b ;
vector<int> adj[N] ;
vector<int> v ,ans ;
int len = 1e9 ;
int vis[N] ,pos[N] ,vid ;
void dfs(int p,int root,bool work){
    if(work && p==root){
        if(v.size() < len) len = v.size() ,ans = v ;
        return ;
    }
    if(vis[p]==vid) return ;
    vis[p] = vid ;
    pos[p] = v.size() ;
    v.push_back(p);
    for(int ch:adj[p]) dfs(ch,root,1) ;
    v.pop_back();
}
int main(){
    scanf("%d%d",&n,&m);
    while(m--){
        scanf("%d%d",&a,&b);
        adj[a].push_back(b);
    }
    for(int i=1;i<=n;++i){
        ++vid ;
        dfs(i,i,0);
    }
    if(len>n) return cout << -1,0 ;
    cout << len << endl ;
    for(int go:ans)printf("%d\n",go);
    return 0;
}
