#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

void find_cycle(vector<vector<int>>& path, int v, int p, stack<int>& st, vector<int>& vis, vector<int>& cycle) {
	if (cycle.size() > 0)return;
	for (int i = 0; i < path[v].size(); ++i) {
		if (vis[path[v][i]] == 1) {
			if (cycle.size() == 0) {
				cycle.push_back(v);
				while (!st.empty() && st.top() != path[v][i]) {
					cycle.push_back(st.top());
					st.pop();
				}
				cycle.push_back(path[v][i]);
				reverse(cycle.begin(), cycle.end());
			}
			return;
		} else if (vis[path[v][i]] == 0) {
			vis[path[v][i]] = 1;
			st.push(v);
			find_cycle(path, path[v][i], v, st, vis, cycle);
			vis[path[v][i]] = 2;
			if (!st.empty())st.pop();
		}
	}
	return;
}

vector<int> get_cycle(vector<vector<int>>& path) {
	int n = path.size();
	vector<int> vis(n, 0);
	vector<int> cycle;
	REP(i, n) {
		if (vis[i] == 0) {
			vis[i] = 1;
			stack<int> st;
			find_cycle(path, i, -1, st, vis, cycle);
			vis[i] = 2;
		}
		if (cycle.size() > 0) {
			return cycle;
		}
	}
	return cycle;
}



struct ListNode {
	int val;
	int index;
	ListNode* next;
	ListNode(int x, int index) : val(x),index(index), next(NULL) {}
};
ListNode* push(int n,int i, ListNode* l) {
	ListNode* rtn = new ListNode(n, i);
	l->next = rtn;
	return rtn;
}

int main() {
	IOS;
	int n, m;
	cin >> n >> m;
	vector<int> a(m), b(m);
	vector<vector<int>> path(n);
	REP(i, m) {
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
		path[a[i]].push_back(b[i]);
	}
	vector<int> cycle = get_cycle(path);
	if (cycle.size()==0) {
		put(-1);
		return 0;
	}
	ListNode* now = new ListNode(cycle[0],0);
	vector<ListNode*> table(n,NULL);
	table[cycle[0]] = now;
	REP(i, cycle.size() - 1) {
		now = push(cycle[i + 1], i + 1, now);
		table[cycle[i + 1]] = now;
	}
	now->next = table[cycle[0]];
	now = now->next;
	bool flag = true;
	while (flag) {
		flag = false;
		ListNode* start = now;
		REP(i, path[now->val].size()) {
			int temp = path[now->val][i];
			if (table[temp]&&table[temp]!=now->next) {
				flag = true;
				ListNode* temp2 = table[temp];
				REP(j, n) {
					table[j] = NULL;
				}
				for (ListNode* j = temp2; j != now; j = j->next) {
					table[j->val] = j;
				}
				table[now->val] = now;
				now->next = temp2;
				break;
			}
		}
		for (ListNode* k = now->next; !flag && k != start; k = k->next) {
			REP(i, path[k->val].size()) {
				int temp = path[k->val][i];
				if (table[temp] && table[temp] != k->next) {
					flag = true;
					ListNode* temp2 = table[temp];
					REP(j, n) {
						table[j] = NULL;
					}
					for (ListNode* j = temp2; j != k; j = j->next) {
						table[j->val] = j;
					}
					table[k->val] = k;
					k->next = temp2;
					now = k;
					break;
				}
			}
		}
	}
	int res = 0;
	ListNode* root=NULL;
	REP(i, n) {
		if (table[i]) {
			res++;
			root = table[i];
		}
	}
	put(res);
	now = root;
	while (true) {
		put(now->val + 1);
		now = now->next;
		if (now == root)break;
	}
	return 0;
}


Measured memory_bytes: 512