#include <numeric>
#include <stack>
#include <queue>
#include <random>
#include <unordered_set>
#include <unordered_map>
#include <iostream>
#include <sstream>
#include <vector>
#include <cstdio>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <string>
#include <bitset>
#include <cassert>
#include <cmath>
#include <algorithm>
#include <tuple>
#include <sstream>

using namespace std;

#define forn(a, e) for (int a = 0; a < (int)(e); a++)
#define forr(a, s, e) for (int a = s; a < (int)(e); a++)
#define fore(e, a) for (auto& e : a)

#ifdef LOCAL
#define logv(a) {cerr << #a << " = "; fore(e, a) {cerr << e << " ";} cerr << "\n";}
#define logvp(a) {cerr << #a << " = "; fore(e, a) {cerr << "(" << e.first << ", " << e.second << ") ";} cerr << "\n";}
#define logvv(a) {cerr << #a << " = \n"; fore(r, a) { fore(e, r) {cerr << e << " ";} cerr << "\n";} }
#define logvf(a, field) {cerr << #a"."#field << " = \n"; fore(e, a) { cerr << e.field << " ";} cerr << "\n"; }
#define logs(a) cerr << #a << " = " << (a) << "\n";
#define logss(a, b) cerr << #a << " = " << (a) << ", " << #b << " = " << (b) << "\n";
#define logp(a) cerr << #a << " = " << "(" << a.first << ", " << a.second << ")" << "\n";
#define cond(pred, stmt) if (pred) { stmt }
#else
#define logv(a)
#define logvp(a)
#define logvv(a)
#define logvf(a, field)
#define logs(a)
#define logss(a, b)
#define logp(a)
#define cond(pred, stmt)
#endif

using i64 = long long;
using iip = pair<int, int>;
using ivec = vector<int>;
using llvec = vector<i64>;
using svec = vector<string>;

template<typename T, typename Dim>
auto make_vec(T value, Dim dim) { return vector<T>(dim, value); }
template<typename T, typename Dim1, typename... Dim>
auto make_vec(T value, Dim1 dim1, Dim... dims) { return make_vec(make_vec(value, dims...), dim1); }

template<typename T>
bool uax(T& v, const T& newv) { if (v < newv) { v = newv; return true; } else return false; }
template<typename T>
bool uin(T& v, const T& newv) { if (v > newv) { v = newv; return true; } else return false; }

template<typename T>
istream& operator>>(istream& is, vector<T>& c) { for (auto& e : c) is >> e; return is; }

// template<typename ...T>
// istream& read(T&... args) { return (cin >> ... >> args); }

static mt19937 rande(123123);
template<typename T>
T rand_int(T from, T to) { uniform_int_distribution<T> distr(from, to); return distr(rande); }

i64 gcd (i64 a, i64 b) {
	if (b == 0) {
		return a;
    } else {
		return gcd(b, a % b);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, m;
    while (cin >> n >> m) {
        vector<vector<int>> g(n + 1);
        forn(i, m) {
            int a, b;
            cin >> a >> b;
            g[a].push_back(b);
        }

        ivec used(n + 1);
        set<int> ans;
        ivec pos(n + 1, -1);
        function<bool(int, ivec&)> dfs = [&](int u, ivec& path) {
            if (used[u] == 1) {
                set<int> pathv;
                forr(i, pos[u], path.size()) {
                    pathv.insert(path[i]);
                }
                fore(u, pathv) {
                    int c = 0;
                    fore(uu, g[u]) {
                        if (pathv.count(uu)) {
                            c++;
                        }
                        if (c > 1) {
                            return false;
                        }
                    }
                }
                ans = pathv;
                return true;
            } else if (used[u] == 2) {
                return false;
            }

            pos[u] = path.size();
            path.push_back(u);

            used[u] = 1;
            fore(v, g[u]) {
                if (dfs(v, path)) {
                    return true;
                }
            }
            pos[u] = -1;
            path.pop_back();
            used[u] = 2;
            return false;
        };
        ivec path;
        forr(i, 1, n + 1) {
            used.assign(n + 1, 0);
            pos.assign(n + 1, -1);
            if (dfs(i, path)) {
                break;
            }
        }

        if (ans.empty()) {
            cout << -1 << endl;
        } else {
            cout << ans.size() << "\n";
            fore(v, ans) {
                cout << v << "\n";
            }
        }
    }
}


Measured memory_bytes: 640