#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

bool check_loop(vector<bool> &seen, vector<bool> &finished, deque<int> &ps, const VVI &es, int s, int i) {
    seen[i] = true;
    ps.push_back(i);
    for (auto &&dst: es[i]) {
        if (finished[dst]) continue;

        if (seen[dst] && !finished[dst]) {
            return true;
        }

        if (check_loop(seen, finished, ps, es, s, dst)) return true;
    }
    ps.pop_back();
    finished[i] = true;

    return false;
}

PII validate(const deque<int> &ps, const VVI &es, const map<int,int> &ri) {
    int n = es.size();
    int from = -1, to = -1;
    REP(i,0,ps.size()) {
        for (const int &dst: es[ps[i]]) {
            if (dst == ps[(i+1)%ps.size()]) continue;
            //if (ri.count(dst) != 0) return MP(ps[i], dst);
            if (ri.count(dst) != 0) {
                from = ps[i];
                to = dst;
            }
        }         
    }

    return MP(from,to);
}

void solve() {
    int n,m;
    cin >> n >> m;
    VVI es(n);
    int a,b;
    REP(i,0,m) {
        cin >> a >> b;
        --a; --b;
        es[a].push_back(b);
    }

    REP(i,0,n) {
        vector<bool> seen(n), finished(n);
        deque<int> ps;
        ps.push_back(i);
        if (check_loop(seen,finished,ps,es,i,i)) {
            int start = 0, last = ps.size() - 1;
            for (;!ps.empty();) {
                map<int,int> ri;
                REP(i,0,ps.size()) ri[ps[i]] = i;

                auto ret = validate(ps,es,ri);
                if (ret == MP(-1,-1)) break;

                start = ret.second;
                last = ret.first;
                int sp = ri[start], lp = ri[last];

                deque<int> nps;
                nps.push_back(ps[lp]);
                for (int j = sp; j != lp ; j = (j + 1) % ps.size()) {
                    nps.push_back(ps[j]);
                }
                ps = nps;
            }

            if (ps.size() == 0) continue;

            //dump(ps.size());
            cout << ps.size() << endl;
            REP(i,0,ps.size()) cout << ps[i] + 1 << endl;
            return;
        }
    }
    cout << -1 << endl;
}

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

Measured memory_bytes: 384