#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 1000000007
// #define int long long
#define ll long long
#define EPS 0.00000000000001
#define ld long double
#define inf 200000000
#define N 1000001


int32_t main()
{
    IOS;

    int n,m;
    cin >> n >> m;
    vector<int> par(n+1),dist(n+1);
    set<int> g[n+1];
    for(int i = 1;i <= m;i++)
    {
        int a,b;
        cin  >> a >> b;
        g[a].insert(b);
    }
    bool ch = 0;
    set<int> ans;
    for(int i = 1;i <= n;i++)
    {
        queue<int> q;
        q.push(i);
        for(int j = 1;j <= n;j++)
        {
            dist[j] = n + 2;
        }
        par[i] = i;
        dist[i] = 0;
        
        while(!q.empty())
        {
            int d = q.front();
            q.pop();
            for(auto it : g[d])
            {
                if(dist[it] > dist[d] + 1)
                {
                    dist[it] = dist[d] + 1;
                    par[it] = d;
                    q.push(it);
                }
                if(it == i)
                {
                    
                    while(d != it)
                    {
                        ans.insert(d);
                        d = par[d];
                    }
                    ans.insert(it);
                    ch = 1;
                    break;
                }
            }
            if(ch)
                break;
        }
        if(ch)
            break;
    }
    if(ch == 0)
        cout << -1;
    else
    {
        int shortest_cycle = ans.size();
        int src = *ans.begin();
        for(auto it : ans)
        {
            vector<int> temp;
            for(auto v : g[it])
                if(ans.find(v) == ans.end())
                    temp.push_back(v);
            for(auto v : temp)
                g[it].erase(v);
        }
        for(auto i : ans)
        {
            queue<int> q;
            q.push(i);
            for(int j = 1;j <= n;j++)
            {
                dist[j] = n + 2;
            }
            par[i] = i;
            dist[i] = 0;
            
            while(!q.empty())
            {
                int d = q.front();
                q.pop();
                for(auto it : g[d])
                {
                    if(dist[it] > dist[d] + 1)
                    {
                        dist[it] = dist[d] + 1;
                        par[it] = d;
                        q.push(it);
                    }
                    if(it == i)
                    {
                        if(shortest_cycle > dist[d] + 1)
                        {
                            shortest_cycle = dist[d] + 1;
                            src = i;
                        }
                    }
                }
                
            }
        }
        queue<int> q;
        q.push(src);
        for(int j = 1;j <= n;j++)
        {
            dist[j] = n + 2;
        }
        par[src] = src;
        dist[src] = 0;
        
        while(!q.empty())
        {
            int d = q.front();
            q.pop();
            for(auto it : g[d])
            {
                if(dist[it] > dist[d] + 1)
                {
                    dist[it] = dist[d] + 1;
                    par[it] = d;
                    q.push(it);
                }
                if(it == src)
                {
                    vector<int> fans;
                    while(d != src)
                    {
                        fans.push_back(d);
                        d = par[d];
                    }
                    fans.push_back(src);
                    cout << fans.size() << endl;
                    for(auto it : fans)
                        cout << it << endl;
                    return 0;
                }
            }
            
        }

    }
    return 0;
}
 
 

Measured memory_bytes: 384