//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

inline ll floor(ll a, ull b)
{
	ll llb = b;
	if (a >= 0)
	{
		return a / llb;
	}
	else
	{
		return - ( (-a + llb - 1) / llb);
	}
}

inline ll ceil(ll a, ull b)
{
	ll llb = b;
	if (a >= 0)
	{
		return (a + llb - 1) / llb;
	}
	else
	{
		return - (-a / llb);
	}
}

inline ll getLowestOneBit(ll a)
{
	return a & (-a);
}

inline ll getHighestOneBit(ll a)
{
	while ((a & (a - 1)) != 0)
	{
		a = a & (a - 1);
	}
	return a;
}

inline bool isPower2(ull a)
{
	if (a == 0)
	{
		return false;
	}
	return !(a & (a - 1));
}

inline ll getSpecifiedBit(ll a, unsigned bit)
{
	return (a & (1LL << bit)) >> bit;
}

// computational complexity: o(log(max(a, b))) 
inline ull getGcd(ull a, ull b)
{
	if (b == 0)
	{
		return a;
	}
	return getGcd(b, a % b);
}

template<class Integer>
inline Integer getPower(Integer base, ull exponential)
{
	Integer result = 1;
	while (exponential >= 1)
	{
		if (exponential & 1)
		{
			result = result * base;
		}
		base = base * base;
		exponential >>= 1;
	}

	return result;
}

vector<ll> z_algorithm(string S) {
	vector<ll> As(S.size());

	ll base_pos = 0;
	for (ll curr_pos = 1; curr_pos < S.size(); curr_pos++)
	{
		if (curr_pos + As[curr_pos - base_pos] < base_pos + As[base_pos])
		{
			As[curr_pos] = As[curr_pos - base_pos];
		}
		else
		{
			int check_pos = max(0LL, base_pos + As[base_pos] - curr_pos);
			while (curr_pos + check_pos < S.size() && S[check_pos] == S[curr_pos + check_pos]) ++check_pos;
			As[curr_pos] = check_pos;
			base_pos = curr_pos;
		}
	}
	As[0] = S.size();

	return As;
}

enum struct Status
{
	NOT_VISITED,
	ACTIVE,
	FINISHED
};

ll visit(ll i, const vector<vector<ll>>& edges, vector<Status>& node_status) {
	if (node_status[i] == Status::ACTIVE) return i;
	else if (node_status[i] == Status::NOT_VISITED)
	{
		ll node;
		node_status[i] = Status::ACTIVE;
		for (ll j = 0; j < edges[i].size(); ++j)
		{
			if ((node = visit(edges[i][j], edges, node_status)) != -1 ) return node;
		}
		node_status[i] = Status::FINISHED;
	}
	return -1;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll N, M;
	cin >> N >> M;
	
	vector<vector<ll>> edges(N);
	ll a, b;
	for (ll i = 0; i < M ; ++i)
	{
		cin >> a >> b;
		--a, --b;
		edges[a].emplace_back(b);
	}

	vector<Status> node_status(N, Status::NOT_VISITED);
	ll node = 0;
	for (ll i = 0 ; i < N; ++i)
	{
		if (node_status[i] == Status::NOT_VISITED)
		{
			if ((node = visit(i, edges, node_status)) != -1 ) break;
		}
	}

	if (node == -1)
	{
		cout << -1 << endl;
		return 0;
	}

	ll begin = -1;
	vector<ll> nodes;
	while (true)
	{
		nodes.emplace_back(node);
		ll next_node = 0;
		begin = -1;
		for (ll j = 0; j < edges[node].size(); ++j)
		{
			if (find(nodes.begin(), nodes.end(), edges[node][j]) != nodes.end())
			{
				begin = max(begin, static_cast<ll>(distance(nodes.begin(), find(nodes.begin(), nodes.end(), edges[node][j]))));
			}
			if (node_status[edges[node][j]] == Status::ACTIVE) next_node = edges[node][j];
		}
		if (begin != -1) goto loop_end;
		node = next_node;
	}
loop_end:

	cout << nodes.size() - begin << endl;
	for (ll i = begin; i < nodes.size(); ++i)
	{
		cout << nodes[i] + 1 << endl;
	}

	return 0;
}


Measured memory_bytes: 384