#include <bits/stdc++.h>
using namespace std;
#if __has_include(<boost/multiprecision/cpp_int.hpp>)
	#include <boost/multiprecision/cpp_int.hpp>
	#include <boost/multiprecision/cpp_dec_float.hpp>
	using bll = boost::multiprecision::cpp_int;
	using bdouble = boost::multiprecision::cpp_dec_float_100;
	using namespace boost::multiprecision;
#endif
#ifdef LOCAL_DEV
	void debug_impl() { std::cerr << '\n'; }
	template<typename Head, typename... Tail> void debug_impl(Head head, Tail... tail) { std::cerr << " " << head << (sizeof...(tail) ? "," : ""); debug_impl(tail...); }
	#define debug(...) do { std::cerr << "(" << #__VA_ARGS__ << ") ="; debug_impl(__VA_ARGS__); } while (false)
#else
	#define debug(...) do {} while (false)
#endif
#ifdef LOCAL_TEST
	#define BOOST_STACKTRACE_USE_ADDR2LINE
	#define BOOST_STACKTRACE_ADDR2LINE_LOCATION /usr/local/opt/binutils/bin/addr2line
	#define _GNU_SOURCE
	#include <boost/stacktrace.hpp>
	namespace std {
		template<typename T> class dvector : public std::vector<T> {
		public:
			dvector() : std::vector<T>() {}
			explicit dvector(size_t n, const T& value = T()) : std::vector<T>(n, value) {}
			dvector(const std::vector<T>& v) : std::vector<T>(v) {}
			dvector(const std::initializer_list<T> il) : std::vector<T>(il) {}
			dvector(const std::string::iterator first, const std::string::iterator last) : std::vector<T>(first, last) {}
			dvector(const typename std::vector<T>::iterator first, const typename std::vector<T>::iterator last) : std::vector<T>(first, last) {}
			dvector(const typename std::vector<T>::reverse_iterator first, const typename std::vector<T>::reverse_iterator last) : std::vector<T>(first, last) {}
			dvector(const typename std::vector<T>::const_iterator first, const typename std::vector<T>::const_iterator last) : std::vector<T>(first, last) {}
			dvector(const typename std::vector<T>::const_reverse_iterator first, const typename std::vector<T>::const_reverse_iterator last) : std::vector<T>(first, last) {}
			T& operator[](size_t n) {
				try { return this->at(n); } catch (const std::exception& e) {
					std::cerr << boost::stacktrace::stacktrace() << '\n'; return this->at(n);
				}
			}
			const T& operator[](size_t n) const {
				try { return this->at(n); } catch (const std::exception& e) {
					std::cerr << boost::stacktrace::stacktrace() << '\n'; return this->at(n);
				}
			}
		};
	}
	class dbool {
	private:
		bool boolvalue;
	public:
		dbool() : boolvalue(false) {}
		dbool(bool b) : boolvalue(b) {}		
		dbool(const dbool&) = default;
		dbool(dbool&&) = default;
		dbool& operator=(const dbool&) = default;
		dbool& operator=(dbool&&) = default;
		operator bool&() { return boolvalue; }
		operator const bool&() const { return boolvalue; }
	};
	template<typename T> std::ostream& operator<<(std::ostream& s, const std::dvector<T>& v) {
		for (size_t i = 0; i < v.size(); ++i){ s << v[i]; if (i < v.size() - 1) s << "\t"; } return s; }
	template<typename T> std::ostream& operator<<(std::ostream& s, const std::dvector<std::dvector<T>>& vv) {
		s << "\\\n"; for (size_t i = 0; i < vv.size(); ++i){ s << vv[i] << "\n"; } return s; }
	template<typename T> std::ostream& operator<<(std::ostream& s, const std::deque<T>& v) {
		for (size_t i = 0; i < v.size(); ++i){ s << v[i]; if (i < v.size() - 1) s << "\t"; } return s; }
	template<typename T> std::ostream& operator<<(std::ostream& s, const std::set<T>& se) {
		s << "{ "; for (auto itr = se.begin(); itr != se.end(); ++itr){ s << (*itr) << "\t"; } s << "}"; return s; }
	template<typename T> std::ostream& operator<<(std::ostream& s, const std::multiset<T>& se) {
		s << "{ "; for (auto itr = se.begin(); itr != se.end(); ++itr){ s << (*itr) << "\t"; } s << "}"; return s; }
	template <typename T, size_t N> std::ostream& operator<<(std::ostream& s, const std::array<T, N>& a) {
		s << "{ "; for (size_t i = 0; i < N; ++i){ s << a[i] << "\t"; } s << "}"; return s; }
	template<typename T1, typename T2> std::ostream& operator<<(std::ostream& s, const std::map<T1, T2>& m) {
		s << "{\n"; for (auto itr = m.begin(); itr != m.end(); ++itr){ s << "\t" << (*itr).first << " : " << (*itr).second << "\n"; } s << "}"; return s; }
	template<typename T1, typename T2> std::ostream& operator<<(std::ostream& s, const std::pair<T1, T2>& p) {
		return s << "(" << p.first << ", " << p.second << ")"; }
	#define vector dvector
	#define bool dbool
	class SIGFPE_exception : std::exception {};
	class SIGSEGV_exception : std::exception {};
	void catch_SIGFPE([[maybe_unused]] int e) { std::cerr << boost::stacktrace::stacktrace() << '\n'; throw SIGFPE_exception(); }
	void catch_SIGSEGV([[maybe_unused]] int e) { std::cerr << boost::stacktrace::stacktrace() << '\n'; throw SIGSEGV_exception(); }
	signed convertedmain();
	signed main() { signal(SIGFPE, catch_SIGFPE); signal(SIGSEGV, catch_SIGSEGV); return convertedmain(); }
	#define main() convertedmain()
#endif
//#define int long long
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=(1<<31)-1=2147483647
constexpr ll INF = (ll)1e18;//(1LL<<63)-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr ll dx[4] = {1, 0, -1, 0};
constexpr ll dy[4] = {0, 1, 0, -1};
constexpr ll dx8[8] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr ll dy8[8] = {0, 1, 0, -1, 1, -1, 1, -1};
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define rrep(i, n)   for(ll i=(n)-1; i>=0; --i)
#define rrepeq(i, n) for(ll i=(n)  ; i>=1; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
void p() { std::cout << '\n'; }
template<typename Head, typename... Tail> void p(Head head, Tail... tail) { std::cout << head << (sizeof...(tail) ? " " : ""); p(tail...); }
template<typename T> inline void pv(std::vector<T>& v) { for(ll i=0, N=v.size(); i<N; i++) std::cout << v[i] << " \n"[i==N-1]; }
template<typename T> inline bool chmax(T& a, T b) { return a < b && (a = b, true); }
template<typename T> inline bool chmin(T& a, T b) { return a > b && (a = b, true); }
template<typename T> inline void uniq(std::vector<T>& v) { v.erase(std::unique(v.begin(), v.end()), v.end()); }

/*-----8<-----template-----8<-----*/

//(searchcycleから呼ばれる用)gに閉路を検出したときtrueを返す
//seen[v] := 行きがけ順の意味で v が訪問済みであることを表す 
//　　　　　　(帰りがけ順の意味で v が訪問済みかどうかは定かではない)
//finished[v] := 帰りがけ順の意味で v が訪問済みであることを表す
//history := 探索した頂点の履歴
ll dfscycle(vector<vector<ll>> &g, ll v, vector<bool> &seen, vector<bool> &completed, vector<ll> &history){
	history.push_back(v);
	seen[v]=true;
	for(ll nextv:g[v]){
		//if(nextv==p)continue;//無向グラフの場合はコメントアウト外すこと
		if(completed[nextv])continue;
		if(seen[nextv] && !completed[nextv])return nextv;
		ll returnedv=dfscycle(g,nextv,seen,completed,history);
		if(returnedv!=-1)return returnedv;
	}
	history.pop_back();
	completed[v]=true;
	return -1;
}

//頂点vが含まれる閉路を構成する頂点を返す、閉路がない場合は空のvectorが返される
vector<ll> searchcycle(vector<vector<ll>> &g, ll v, vector<bool> &seen, vector<bool> &completed){
	vector<ll> history;
	ll returnedv=dfscycle(g,v,seen,completed,history);
	if(returnedv==-1)return vector<ll>();

	vector<ll> cyclev;
	while(!history.empty()){
		ll v=history.back();
		cyclev.push_back(v);
		history.pop_back();
		if(v==returnedv)break;
	}
	reverse(cyclev.begin(), cyclev.end());
	return cyclev;
}


//弦を持たない最小な閉路を構成する頂点を返す
vector<ll> minimizecycle(vector<vector<ll>> &g, vector<ll> cyclev){
	ll gsize=g.size();
	vector<ll> mincyclev=cyclev;
	while(1){
		ll csize=mincyclev.size();
		ll fromindex=-1,toindex=-1;
		vector<ll> order(gsize,-1);
		for(ll i=0;i<csize;i++)order[mincyclev[i]]=i;
		for(ll i=0;i<csize;i++){
			for(ll nextv:g[mincyclev[i]]){
				//nextvが閉路を構成する頂点 && nextvは想定している閉路の次の頂点でない
				if(order[nextv]!=-1 && mincyclev[(i+1)%csize]!=nextv){
					fromindex=i;
					toindex=order[nextv];
				}
			}
		}

		if(fromindex==-1)break;

		vector<ll> newcyclev;
		newcyclev.push_back(mincyclev[fromindex]);
		ll index=toindex;
		while(index!=fromindex){
			newcyclev.push_back(mincyclev[index]);
			index=(index+1)%csize;
		}
		mincyclev=newcyclev;
	}
	return mincyclev;
}

/*-----8<-----library-----8<-----*/

signed main() {
	//ABC142F
	//https://atcoder.jp/contests/abc142/tasks/abc142_f
	ll N,M;
	cin>>N>>M;

	vector<vector<ll>> g(N);
	rep(i,M){
		ll a,b;
		cin>>a>>b;
		a--;b--;
		g[a].push_back(b);
	}

	vector<bool> seen(N,false);
	vector<bool> completed(N,false);
	vector<ll> cyclev;
	if([&]{
		rep(i,N){
			if(seen[i])continue;
			cyclev = searchcycle(g, i, seen, completed);
			if(cyclev.size()>0)return false;
		}
		return true;
	}()){
		p(-1);
		return 0;
	}

	vector<ll> mincyclev = minimizecycle(g, cyclev);
	
	p(mincyclev.size());
	rep(i,mincyclev.size())p(1+mincyclev[i]);
	return 0;
}


Measured memory_bytes: 384