#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <map>
using namespace std;
typedef pair<int, int> P;

int main()
{
    int n, m;
    cin >> n >> m;
    int a[2003], b[2003];
    vector<int> v[1002];
    vector<int> r[1002];
    map<P, bool> mp;
    int l[2003] {0};
    for(int i = 0; i < m; i++){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        l[a[i]]++;
        v[a[i]].push_back(b[i]);
        r[b[i]].push_back(a[i]);
        mp[P(a[i], b[i])] = true;
    }
    bool sink = true;
    while(sink){
        sink = false;
        for(int i = 0; i < n; i++){
            if(l[i] == 0){
                queue<int> que;
                que.push(i);
                while(que.size()){
                    int now = que.front();
                    que.pop();
                    for(int next : r[now]){
                        if(mp[P(next, now)]){
                            sink = true;
                            mp[P(next, now)] = false;
                            l[next]--;
                            if(l[next] == 0) que.push(next);
                        }
                    }
                }
            }
        }
    }
    bool dag = true;
    int s;
    for(int i = 0; i < n; i++){
        if(l[i] != 0){
            dag = false;
            s = i;
            int now = s;
            for(int j = 0; j < n; j++){
                for(int next : v[now]){
                    if(l[next] != 0){
                        now = next;
                        break;
                    }
                }
                if(s == now) break;
            }
            if(s == now) break;
        }
    }
    int now = s;
    vector<int> cir;
    do{
        for(int next : v[now]){
            if(l[next] != 0){
                now = next;
                cir.push_back(now);
                break;
            }
        }
    }while(now != s);
    if(dag){
        cout << -1 << endl;
        return 0;
    }
//    for(int i = 0; i < n; i++) cout << l[i] << endl;
    bool inc[1002];
    int next[1002];
    fill(inc, inc + n, false);
    int k = cir.size();
    for(int i = 0; i < k; i++){
        inc[cir[i]] = true;
        next[cir[i]] = cir[(i + 1) % k];
    }
//    for(int i = 0; i < k; i++) cout << cir[i] << next[cir[i]] << endl;
    bool up = true;
    while(up){
        up = false;
        for(int i = 0; i < k; i++){
            if(!inc[cir[i]]){
                continue;
            }
            for(int x : v[cir[i]]){
                if(inc[x] && x != next[cir[i]]){
                    up = true;
                    int ima = cir[i];
                    while(next[ima] != x){
                        ima = next[ima];
                        inc[ima] = false;
                    }
                    next[cir[i]] = x;
                    break;
                }
            }
        }
    }
    int st;
    int ans = 0;
    for(int i = 0; i < k; i++){
        if(inc[cir[i]]) ans++;
    }
    cout << ans << endl;
    for(int i = 0; i < k; i++){
        if(inc[cir[i]]){
            st = cir[i];
            break;
        }
    }
    int nnow = st;
    do{
        cout << nnow + 1 << endl;
        nnow = next[nnow];
    }while(nnow != st);
}

Measured memory_bytes: 512