#include <bits/stdc++.h>
using namespace std;


//TEMPLATE
#define pb                push_back
#define mp                make_pair
#define ll                long long
#define ld                long double
#define pii               pair <ll, ll>
#define piii              pair <ll, pii>
#define F                 first
#define S                 second

#define newline           printf("\n")
#define minusone          printf("-1\n")
#define zeroo             printf("0\n")
#define scl1(a)           scanf("%lld", &a)
#define scl2(a, b)        scanf("%lld %lld", &a, &b)
#define scl3(a, b, c)     scanf("%lld %lld %lld", &a, &b, &c)
#define prl1(a)           printf("%lld\n", a)
#define prl2(a, b)        printf("%lld %lld\n", a, b)
#define ssl1(s)           scanf(" %[^\n]", s)
#define scd1(a)           scanf("%lf", &a)
#define scd2(a, b)        scanf("%lf %lf", &a, &b)
#define prd(a)            printf("%lf\n", a)
#define prld(a)           printf("%Lf\n", a)
#define prcase(cs)        printf("Case %lld: ", cs)
#define cin1(a)           cin >> a
#define cin2(a, b)        cin >> a >> b
#define cin3(a, b, c)     cin >> a >> b >> c
#define cin4(a, b, c, d)  cin >> a >> b >> c >> d
#define cot1(a)           cout << a << "\n"
#define cot2(a, b)        cout << a << " " << b << "\n"
#define cot3(a, b, c)     cout << a << " " << b << " " << c << "\n"
#define cot4(a, b, c, d)  cout << a << " " << b << " " << c << " " << d << "\n"
#define cotline           cout << "\n"
#define cotminus          cout << "-1\n"
#define cot0              cout << "0\n"
#define cotyes            cout << "YES\n"
#define cotno             cout << "NO\n"
#define cotcase(cs)       cout << "Case " << cs << ": "

#define reversed(s)       reverse(s.begin(), s.end())
#define asort(s)          sort(s.begin(), s.end())
#define dsort(s)          sort(s.rbegin(), s.rend())
#define all(s)            s.begin(), s.end()
#define uniq(s)           s.resize(distance(s.begin(),unique(s.begin(), s.end())))
#define found(s, x)       (s.find(x) != s.end())

#define for0(i, n)        for (i = 0; i < n; i++)
#define for1(i, n)        for (i = 1; i <= n; i++)
#define fora(i, a, b)     for (i = a; i <= b; i++)
#define forb(i, b, a)     for (i = b; i >= a; i--)
#define fori(it, s)       for(auto it = s.begin(); it != s.end(); it++)

#define FR                ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ms(a, x)          memset(a, x, sizeof a)
#define bitcount(n)       __builtin_popcountll(n)

//#define pi              3.1415926536
#define pi                acos(-1)

const ll INF = LLONG_MAX;
const ll SZ = 2e3+5;
const ll mod = 1e9+7;

/**
6 9
1 5
1 2
2 6
2 3
3 4
3 1
6 3
4 1
5 2
*/

ll n, m, cycle;
struct data {
    ll u, v;
} edg[SZ];
vector <ll> sg, adj[SZ];
ll vis[SZ];
bool f[SZ];

void dfs(ll u, ll p) {
    if(vis[u] == 2 || f[u] || cycle) return;
    if(vis[u] == 1) {
        cycle = 1;
        return;
    }

    vis[u] = 1;
    for(auto v: adj[u]) {
        dfs(v, u);
    }
    vis[u] = 2;
}

int main() {
    ll cs = 0, tc = 1, x, y, z, i, j, k, g, p, q, ans = 0, sum = 0, c = 0, t = 0;
//    ll a, b, d;
    string s, s1, s2;

    cin2(n, m);
    for1(i, m) {
        cin2(x, y);
        adj[x].pb(y);
    }

    for1(i, n) {
        if(!vis[i]) dfs(i, 0);
    }

    if(!cycle) {
        cotminus;
        return 0;
    }

    for1(i, n) {
        f[i] = 1;
        cycle = 0;
        ms(vis, 0);

        for1(j, n) if(!vis[j]) dfs(j, 0);

        if(!cycle) {
            f[i] = 0;
            sg.pb(i);
        }
    }

    cot1(sg.size());
    for(auto v: sg) cot1(v);


    return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)

const int MAX = 1010;

int N, M;
vi G[MAX];

int pos = -1;
bool vis[MAX], fin[MAX];
vi hist;

int idx[MAX];

void dfs(int v) {
    vis[v] = true;
    hist.push_back(v);
    FORE (nv, G[v]) {
        if (fin[nv]) continue;
        if (vis[nv]) {
            pos = nv;
            return;
        }
        dfs(nv);
        if (pos != -1) return;
    }
    hist.pop_back();
    fin[v] = true;
}

void solve() {
    REP (v, N) {
        dfs(v);
        if (pos != -1) break;
    }

    if (pos == -1) {
        cout << -1 << endl;
        return;
    }

    vi cycle;
    while (!hist.empty()) {
        int t = hist.back();
        cycle.push_back(t);
        hist.pop_back();
        if (t == pos) break;
    }
    reverse(ALL(cycle));

    while(1) {
        bool done = false;
        REP (i, MAX) idx[i] = -1;
        REP (i, cycle.size()) idx[cycle[i]] = i;

        REP (i, cycle.size()) {
            int cur = cycle[i];
            FORE (next, G[cur]) if (idx[next] >= 0) {
                if (idx[next] == (idx[cur] + 1) % cycle.size()) continue;

                vi v;
                bool get = false;
                for (int r = 0;; r++) {
                    if (cycle[r%cycle.size()] == next) get = true;
                    if (get){
                        v.push_back(cycle[r%cycle.size()]);
                        if (cycle[r%cycle.size()] == cur) break;
                    } 
                }

                cycle = v;
                done = true;
                break;
            }
            if (done) break;
        }
        if (!done) break;
    }

    cout << cycle.size() << endl;
    FORE (r, cycle) cout << r+1 << "\n";
    return;
}

int main() {
    cin >> N >> M;
    REP (i, M) {
        int a, b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
    }
    solve();
}