Problem: Given is a directed graph G with N vertices and M edges.
The vertices are numbered 1 to N, and the i-th edge is directed from Vertex A_i to Vertex B_i.
It is guaranteed that the graph contains no self-loops or multiple edges.

Determine whether there exists an induced subgraph (see Notes) of G such that the in-degree and out-degree of every vertex are both 1. If the answer is yes, show one such subgraph.
Here the null graph is not considered as a subgraph.

Constraints

* 1 \leq N \leq 1000
* 0 \leq M \leq 2000
* 1 \leq A_i,B_i \leq N
* A_i \neq B_i
* All pairs (A_i, B_i) are distinct.
* All values in input are integers.

Input

Input is given from Standard Input in the following format:


N M
A_1 B_1
A_2 B_2
:
A_M B_M


Output

If there is no induced subgraph of G that satisfies the condition, print `-1`. Otherwise, print an induced subgraph of G that satisfies the condition, in the following format:


K
v_1
v_2
:
v_K


This represents the induced subgraph of G with K vertices whose vertex set is \\{v_1, v_2, \ldots, v_K\\}. (The order of v_1, v_2, \ldots, v_K does not matter.) If there are multiple subgraphs of G that satisfy the condition, printing any of them is accepted.

Examples

Input

4 5
1 2
2 3
2 4
4 1
4 3


Output

3
1
2
4


Input

4 5
1 2
2 3
2 4
1 4
4 3


Output

-1


Input

6 9
1 2
2 3
3 4
4 5
5 6
5 1
5 2
6 1
6 2


Output

4
2
3
4
5

Solution (in JAVA):

Solution:
import java.util.*;

class Main {
	Scanner sc;
	int N, M;
	List<Integer>[] to;
	int[] marker;

	public Main() {
		sc = new Scanner(System.in);
	}
	
	@SuppressWarnings("unchecked")
	private void calc() {
		N = sc.nextInt();
		M = sc.nextInt();
		to = new ArrayList[N];
		for (int i = 0; i < N; i++) to[i] = new ArrayList<>();
		for (int i = 0; i < M; i++) {
			int a = sc.nextInt() - 1;
			to[a].add(sc.nextInt()-1);
		}
		marker = new int[N];
		
		Deque<Integer> ans = null;
		for (int s = 0; s < N; s++) {
			if (marker[s] == 2) continue;
			Deque<Integer> b = dfs(s);
			if (b == null) continue;
			ans = b;
			break;
		}
		if (ans == null) {
			System.out.println(-1);
			return;
		}
		
		int s = ans.size();
		while ( (ans = shrink(ans)).size() < s ) { s = ans.size(); }
		
		System.out.println(s);
		for (int v : ans) System.out.println(v+1);
	}
	
	private Deque<Integer> dfs(int sv) {
		Deque<Integer> track = new ArrayDeque<>();
		Deque<Integer> q = new ArrayDeque<>();
		q.push(sv);
		
		while (!q.isEmpty()) {
			int v = q.peek();
			marker[v] = 1;
			track.addLast(v);
			boolean stop = true;
			for (int next : to[v]) {
				if (marker[next] == 1) {
					int nv;
					while ( (nv = track.getFirst()) != next) {
						marker[nv] = 3;
						track.removeFirst();
					}
					return track;
				}
				if (marker[next] == 2) continue;
				stop = false;
				q.push(next);
			}
			if (stop) {
				q.pop();
				marker[v] = 2;
				int r = track.removeLast();
			}
		}
		return null;
	}
	
	private Deque<Integer> shrink(Deque<Integer> track) {
		int prev = track.getLast();
		int ev = -1;
	lp:
		for (int now : track) {
			for (int n : to[prev]) {
				if (marker[n] != 1 || n == now) continue;
				ev = n;
				break lp;
			}
			prev = now;
		}
		if (ev == -1) return track;
		for (int i = 0; i < N; i++) marker[i] = 4;
		Iterator<Integer> it = track.iterator();
		int v;
		while (true) {
			v = it.next();
			if (v == ev) break;
		}
		Deque<Integer> ans = new ArrayDeque<>();
		while (v != prev) {
			marker[v] = 1;
			ans.addLast(v);
			if (!it.hasNext()) it = track.iterator();
			v = it.next();
		}
		marker[v] = 1;
		ans.addLast(v);
		return ans;
	}
	
	public static void main(String[] args) {
		new Main().calc();
	}
}