#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>
#include<list>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

ll mypow(ll x,ll n,ll mod = MOD){
    ll ret = 1;
    while(n > 0){
        if(n&1){
            ret = (ret*x)%mod;
        }
        x = (x*x)%mod;
        n >>= 1;
    }
    return ret;
}

ll mygcd(ll a,ll b){
    if(b == 0)return a;
    return mygcd(b,a%b);
}

ll twoPow(ll shiftNum){
    return (1LL << (shiftNum - 1));
}

int dfs(vector<list<ll>> &e,ll x,vector<ll> &s,ll &cv,list<ll> &c){
    if(s[x] == 1){
        cv = x;
        c.push_front(x);
        return 1;
    }
    s[x] = 1;
    for(auto itr = e[x].begin(); itr != e[x].end(); itr++){
        int ret = dfs(e,*itr,s,cv,c);
        if(ret == 1){
            c.push_front(x);
            if(cv == x){
                return 2;
            }else{
                return 1;
            }
        }else if(ret == 2){
            return 2;
        }
    }
    s[x] = 2;
    return 0;
}

bool cutCycle(list<ll> &c,vector<list<ll>> &e,list<ll> &next,ll n){
    vector<bool> used(n+1,false);
    vector<bool> exist(n+1,false);
    for(auto itr = c.begin(); itr != c.end(); itr++){
        exist[*itr] = true;
    }
    for(auto itr = c.begin(); itr != c.end(); itr++){
        used[*itr] = true;
        auto ef = itr;
        ef++;
        if(ef == c.end()){
            break;
        }
        for(auto itr2 = e[*itr].begin(); itr2 != e[*itr].end(); itr2++){
            auto tmp = itr;
            tmp++;
            if(*itr2 != *tmp && exist[*itr2]){
                if(used[*itr2]){
                    next.push_back(*itr);
                    auto citr = c.begin();
                    for(auto titr = c.begin(); titr != c.end(); titr++){
                        if(*titr == *itr2){
                            citr = titr;
                            break;
                        }
                    }
                    for(; ; citr++){
                        next.push_back(*citr);
                        if(citr == itr){
                            return true;
                        }
                    }
                }else{
                    for(auto titr = c.begin(); ; titr++){
                        next.push_back(*titr);
                        if(titr == itr){
                            break;
                        }
                    }
                    auto citr = c.begin();
                    for(auto titr = itr;; titr++){
                        if(*titr == *itr2){
                            citr = titr;
                            break;
                        }
                    }
                    for(; citr != c.end(); citr++){
                        next.push_back(*citr);
                    }
                    return true;
                }
            }
        }
    }
    next = c;
    return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    ll n,m;
    cin >> n >> m;

    vector<list<ll>> edge(n+1);

    for(int i = 0; i < m; i++){
        ll a,b;
        cin >> a >> b;
        edge[a].push_back(b);
    }

    ll cv = -1;
    list<ll> cycle;
    for(int i = 1; i <= n; i++){
        vector<ll> state(n+1,0);
        dfs(edge,i,state,cv,cycle);
        if(cv > 0)break;
    }

    if(cv < 0){
        cout << -1 << endl;
        return 0;
    }

    bool flag = true;
    do{
        list<ll> next;
        flag = cutCycle(cycle,edge,next,n);
        cycle = next;
    }while(flag);

    vector<ll> used(n+1,false);

    for(auto itr = cycle.begin(); itr != cycle.end(); itr++){
        used[*itr] = true;
    }

    ll k = 0;
    for(int i = 0; i < n+1; i++){
        if(used[i]){
            k++;
        }
    }
    cout << k << endl;

    for(int i = 0; i < n+1; i++){
        if(used[i]){
            cout << i << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 512