#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

using namespace std;
struct StronglyConnectedComponents
{
  vector< vector< int > > gg, rg;
  vector< pair< int, int > > edges;
  vector< int > comp, order, used;

  StronglyConnectedComponents(size_t v) : gg(v), rg(v), comp(v, -1), used(v, 0) {}

  void add_edge(int x, int y)
  {
    gg[x].push_back(y);
    rg[y].push_back(x);
    edges.emplace_back(x, y);
  }

  int operator[](int k)
  {
    return (comp[k]);
  }

  void dfs(int idx)
  {
    if(used[idx]) return;
    used[idx] = true;
    for(int to : gg[idx]) dfs(to);
    order.push_back(idx);
  }

  void rdfs(int idx, int cnt)
  {
    if(comp[idx] != -1) return;
    comp[idx] = cnt;
    for(int to : rg[idx]) rdfs(to, cnt);
  }

  void build(vector< vector< int > > &t)
  {
    for(int i = 0; i < gg.size(); i++) dfs(i);
    reverse(begin(order), end(order));
    int ptr = 0;
    for(int i : order) if(comp[i] == -1) rdfs(i, ptr), ptr++;

    t.resize(ptr);
    set< pair< int, int > > connect;
    for(auto &e : edges) {
      int x = comp[e.first], y = comp[e.second];
      if(x == y) continue;
      if(connect.count({x, y})) continue;
      t[x].push_back(y);
      connect.emplace(x, y);
    }
  }
};

int main() {
	int n, m; scanf("%d%d", &n, &m);
	std::vector<std::vector<int>> g(n);
	StronglyConnectedComponents scc(n);
	std::vector<int> x, y;
	for(int i = 0; i < m; i++) {
		int a, b; scanf("%d%d", &a, &b);
		x.push_back(a - 1);
		y.push_back(b - 1);

		g[a - 1].push_back(b - 1);
		scc.add_edge(a - 1, b - 1);
	}
	std::vector<std::vector<int>> t;
	scc.build(t);

	std::vector<std::vector<int>> vec(n);
	for(int i = 0; i < n; i++) vec[scc[i]].push_back(i);

	std::vector<int> ind(n, -1);
	std::vector<bool> used(n, false);
	std::vector<bool> latte(n, false);
	for(int i = 0; i < n; i++) {
		int c = scc[i];
		if(vec[c].size() <= 1) continue;
		if(vec[c].size() == 2) {
			cout << 2 << endl;
			cout << vec[c][0] + 1 << endl << vec[c][1] + 1 << endl;
			return 0;
		}

		int now = i;
		std::set<int> tt;
		std::deque<int> loop;
		loop.push_back(now);
		tt.insert(now);
		while(true) {
			bool f = false;
			for(auto e: g[now]) {
				if(scc[e] != c) continue;
				if(tt.count(e)) {
					while(loop.front() != e) loop.pop_front();
					f = true;
					break;
				} else {
					now = e;
					loop.push_back(e);
					tt.insert(e);
					break;
				}
			}
			if(f) break;
		}
		tt.clear();
		std::vector<int> vec;
		while(!loop.empty()) {
			vec.push_back(loop.front());
			loop.pop_front();
		}

		std::set<int> st;
		for(auto v: vec) st.insert(v);
		for(int i = 0; i < vec.size(); i++) ind[vec[i]] = i;

		std::vector<int> ans;
		for(int i = 0; i < vec.size(); i++) {
			int L = -1, R = -1, v = vec[i];
			for(auto e: g[v]) {
				if(!st.count(e)) continue;

				if(ind[e] < ind[v]) L = std::max(L, ind[e]);
				else R = std::max(R, ind[e]);
			}
			if(L != -1) {
				for(int j = L; j <= i; j++) {
					if(vec[j] == -1) continue;
					ans.push_back(vec[j]);
				}
				break;
			}
			if(R != -1 and R != i + 1) {
				i++;
				while(i < R) {
					st.erase(i);
					vec[i] = -1;
					i++;
				}
			}
		}
		assert(!ans.empty());
		if(ans.empty()) {
			for(auto v: vec) if(v != -1) ans.push_back(v);
		}

		st.clear();
		int cnt = 0;
		for(auto v: ans) st.insert(v);
		for(int i = 0; i < m; i++) {
			if(st.count(x[i]) and st.count(y[i])) {
				cnt++;
			}
		}
		if(cnt != st.size()) continue;
		if(st.size() != ans.size()) continue;

		printf("%d\n", (int)st.size());
		for(auto v: st) printf("%d\n", v + 1);
		return 0;
	}
	printf("-1\n");
	return 0;
}


Measured memory_bytes: 640