#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}
#define DEBUG_VLL(vec) REP(i, vec.size()) cerr<<vec[i]<<(i==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

ll ans = HIGHINF;
set<ll> ansv;

class Graph 
{ 
    int V;    // No. of vertices 
    vvll adj;    // Pointer to an array containing adjacency lists
    bool isCyclicUtil(int v, bool visited[]);  // used by isCyclic() 
public: 
    Graph(int V);   // Constructor
    set<ll> recStack;
    void addEdge(int v, int w);   // to add an edge to graph 
    bool isCyclic();    // returns true if there is a cycle in this graph 
}; 
  
Graph::Graph(int V) 
{ 
    this->V = V; 
    adj.resize(V);
} 
  
void Graph::addEdge(int v, int w) 
{ 
    adj[v].push_back(w); // Add w to v’s list. 
} 
  
// This function is a variation of DFSUtil() in https://www.geeksforgeeks.org/archives/18212 
bool Graph::isCyclicUtil(int v, bool visited[]) 
{
    if(visited[v] == false) 
    { 
        // Mark the current node as visited and part of recursion stack 
        visited[v] = true; 
        recStack.insert(v);
  
        // Recur for all the vertices adjacent to this vertex 
        for(auto i: adj[v]) 
        { 
            if ( !visited[i]) {
                isCyclicUtil(i, visited);
            } else if (recStack.find(i) != recStack.end()) {
                if (ans>recStack.size()) {
                    ans=recStack.size();
                    ansv=recStack;
                }
            }
        } 
  
    } 
    recStack.erase(v); // remove the vertex from recursion stack 
    return false; 
} 
  
// Returns true if the graph contains a cycle, else false. 
// This function is a variation of DFS() in https://www.geeksforgeeks.org/archives/18212 
bool Graph::isCyclic() 
{ 
    // Mark all the vertices as not visited and not part of recursion 
    // stack 
    bool *visited = new bool[V];
  
    // Call the recursive helper function to detect cycle in different 
    // DFS trees 
    for(int i = 0; i < V; i++) {
        for(int i = 0; i < V; i++) visited[i] = false;
        if (isCyclicUtil(i, visited))
            return true;
    }
  
    return false; 
} 

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m; cin >> n >> m;
    Graph g(n);
    REP(i, m) {
        ll a, b; cin >> a >> b;
        g.addEdge(a-1, b-1);
    }
    g.isCyclic();
    if (ans==HIGHINF) cout << "-1\n";
    else {
        cout << ans << '\n';
        for (ll s: ansv) cout << s+1 << '\n';
    }
    return 0;
}


Measured memory_bytes: 512