#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define gcd __gcd
#define F first
#define B begin()
#define E end()
#define ln length()
#define sz size()
#define S second
#define em empty()
#define mp make_pair
#define pb push_back
#define pq priority_queue
#define um unordered_map
#define us unordered_set
#define lb lower_bound
#define ub upper_bound
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define sbits(a) __builtin_popcount(a)
#define lcm(a, b) ((a * b) / gcd(a, b))
#define nani(x) cerr << #x << " is " << x << endl;
#define adde(g, u, v) g[u].pb(v), g[v].pb(u);
#define addew(g, u, v, w) g[u].pb({ v, w }), g[v].pb({ u, w });
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define inf 1000000000
#define mod 1000000007

typedef long long ll;

const int N = 1005;

vector<int> G[N];
int p[N], vis[N], dis[N];
int b, e, d;

int dfs(int x)
{
    vis[x] = 1;
    for (auto& i : G[x]) {
        if (!vis[i]) {
            p[i] = x;
            if (dfs(i))
                return 1;
        } else if (vis[i] == 1) {
            b = i;
            e = x;
            return 1;
        }
    }
    vis[x] = -1;
    return 0;
}

void bfs(int x)
{
    queue<int> q;
    q.push(x);

    while (!q.em) {
        int a = q.front();
        q.pop();

        if (dis[a] - dis[x] > d)
            continue;

        for (auto& i : G[a]) {
            if (i == x) {
                if (dis[a] - dis[x] < d) {
                    d = dis[a] - dis[x];
                    b = x;
                    e = a;
                }
                return;
            }

            if (!vis[i]) {
                dis[i] = dis[a] + 1;
                vis[i] = 1;
                p[i] = a;
                q.push(i);
            }
        }
    }
}

void bfs2(int x)
{
    queue<int> q;
    q.push(x);

    while (!q.em) {
        int a = q.front();
        q.pop();

        for (auto& i : G[a]) {
            if (i == x) {
                b = x;
                e = a;
                return;
            }

            if (!vis[i]) {
                vis[i] = 1;
                p[i] = a;
                q.push(i);
            }
        }
    }
}

int main()
{
    fast;

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    d = inf;
    int n, m;
    cin >> n >> m;

    while (m--) {
        int u, v;
        cin >> u >> v;
        G[u].pb(v);
    }

    for (int i = 1; i <= n; i++) {
        if (vis[i])
            continue;

        int k = dfs(i);

        if (!k)
            continue;

        vector<int> v;
        v.pb(b);

        for (int x = e; x != b; x = p[x])
            v.pb(x);

        for (int& j : v) {
            for (int& x : v)
                vis[x] = p[x] = dis[x] = 0;
            bfs(j);
        }

        for (int x = 1; x <= n; x++)
            vis[x] = p[x] = dis[x] = 0;

        bfs2(b);
        v.clear();
        v.pb(b);

        for (int x = e; x != b; x = p[x])
            v.pb(x);

        cout << v.sz << '\n';

        for (auto& x : v)
            cout << x << '\n';

        return 0;
    }

    cout << -1;

    return 0;
}


Measured memory_bytes: 384