#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;
using ll = long long int;

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N,M;
vector<int> A,B;
vector<vector<int>> toList;
vector<vector<int>> revtoList;
void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path p = __FILE__;
        fs::path input,output;
        input = output = p.parent_path();
        input += string("/input/") + string(p.stem()) + string(".txt");
        output += string("/output/") + string(p.stem()) + string(".txt");
        freopen(input.c_str(), "r", stdin);
        freopen(output.c_str(), "w", stdout);
    #endif
    cin >> N >> M;
    toList.assign(N,vector<int>());
    revtoList.assign(N,vector<int>());
    for (int i = 0; i < M; i++)
    {
        int a,b;
        cin >> a >> b;
        a--,b--;
        A.push_back(a);
        B.push_back(b);
        toList[a].push_back(b);
        revtoList[b].push_back(a);
    }
    
}

// 閉路をいっこ出力する。
vector<bool> seen,finished;
stack<int> hist;
int pos = -1;
bool dfs(int s){
    if(seen[s]) return (pos!=-1);
    seen[s]=true;
    hist.push(s);
    for(auto u:toList[s]){
        if(finished[u]) continue;
        if(seen[u] && !finished[u]){
            pos = u;
            return true;
        }
        dfs(u);
        if(pos!=-1) return true;
    }
    finished[s]=true;
    hist.pop();
    return false;
}

void printCycle(vector<int> c){
    cout << c.size() << "\n";
    for(auto x:c) cout << (x+1) << "\n";
}

int solve(){
    seen.assign(N, false), finished.assign(N, false);
    for (int i = 0; i < N; i++) {
        pos = -1;
        dfs(i);
        if(pos!=-1) break;
    }
    // 有向サイクルのなし
    if(pos==-1){cout << -1 << endl; return 0;}
    // 有向サイクルの復元
    vector<int> cycle;
    while(!hist.empty()){
        int t=hist.top();
        cycle.push_back(t);
        hist.pop();
        if(t==pos) break;
    }
    reverse(cycle.begin(),cycle.end());
    DBG(cycle)
    // サイクル中に弦があれば小さくする。
    while(true){
        int from=-1,to=-1;
        vector<int> ord(N,-1);
        for (int i = 0; i < cycle.size(); i++) ord[cycle[i]]=i;
        for (int i = 0; i < cycle.size(); i++) 
        {
            for(auto nv:toList[cycle[i]]){
                if(nv!=cycle[(i+1)%cycle.size()] && ord[nv]!=-1){
                    from = i, to = ord[nv];
                }
            }
        }
        if(from == -1) break;
        vector<int> ncycle;
        ncycle.push_back(cycle[from]);
        int id=to;
        while(id!=from){
            ncycle.push_back(cycle[id]);
            (++id)%=cycle.size();
        }
        cycle = ncycle;
    }
    printCycle(cycle);
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}


Measured memory_bytes: 512