Sasha lives in a big happy family. At the Man's Day all the men of the family gather to celebrate it following their own traditions. There are n men in Sasha's family, so let's number them with integers from 1 to n.

Each man has at most one father but may have arbitrary number of sons.

Man number A is considered to be the ancestor of the man number B if at least one of the following conditions is satisfied:   A = B;  the man number A is the father of the man number B;  there is a man number C, such that the man number A is his ancestor and the man number C is the father of the man number B. 

Of course, if the man number A is an ancestor of the man number B and A ≠ B, then the man number B is not an ancestor of the man number A.

The tradition of the Sasha's family is to give gifts at the Man's Day. Because giving gifts in a normal way is boring, each year the following happens.  A list of candidates is prepared, containing some (possibly all) of the n men in some order.  Each of the n men decides to give a gift.  In order to choose a person to give a gift to, man A looks through the list and picks the first man B in the list, such that B is an ancestor of A and gives him a gift. Note that according to definition it may happen that a person gives a gift to himself.  If there is no ancestor of a person in the list, he becomes sad and leaves the celebration without giving a gift to anyone. 

This year you have decided to help in organizing celebration and asked each of the n men, who do they want to give presents to (this person is chosen only among ancestors). Are you able to make a list of candidates, such that all the wishes will be satisfied if they give gifts according to the process described above?


-----Input-----

In the first line of the input two integers n and m (0 ≤ m < n ≤ 100 000) are given — the number of the men in the Sasha's family and the number of family relations in it respectively.

The next m lines describe family relations: the (i + 1)^{th} line consists of pair of integers p_{i} and q_{i} (1 ≤ p_{i}, q_{i} ≤ n, p_{i} ≠ q_{i}) meaning that the man numbered p_{i} is the father of the man numbered q_{i}. It is guaranteed that every pair of numbers appears at most once, that among every pair of two different men at least one of them is not an ancestor of another and that every man has at most one father.

The next line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ n), i^{th} of which means that the man numbered i wants to give a gift to the man numbered a_{i}. It is guaranteed that for every 1 ≤ i ≤ n the man numbered a_{i} is an ancestor of the man numbered i.


-----Output-----

Print an integer k (1 ≤ k ≤ n) — the number of the men in the list of candidates, in the first line.

Print then k pairwise different positive integers not exceeding n — the numbers of the men in the list in an order satisfying every of the men's wishes, one per line.

If there are more than one appropriate lists, print any of them. If there is no appropriate list print  - 1 in the only line.


-----Examples-----
Input
3 2
1 2
2 3
1 2 1

Output
-1
Input
4 2
1 2
3 4
1 2 3 3

Output
3
2
1
3



-----Note-----

The first sample explanation:   if there would be no 1 in the list then the first and the third man's wishes would not be satisfied (a_1 = a_3 = 1);  if there would be no 2 in the list then the second man wish would not be satisfied (a_2 = 2);  if 1 would stay before 2 in the answer then the second man would have to give his gift to the first man, but he wants to give it to himself (a_2 = 2).  if, at the other hand, the man numbered 2 would stay before the man numbered 1, then the third man would have to give his gift to the second man, but not to the first (a_3 = 1).

Source: codeforces | Difficulty: HARD
Tags: Tree algorithms

Graph algorithms

Graph traversal

Constructive algorithms


Solutions:
(n, m) = map(int, input().split())
adj = [[] for _ in range(n)]
cp = [-1] * n
for i in range(m):
	(p, c) = map(int, input().split())
	adj[p - 1].append(c - 1)
	cp[c - 1] = p - 1
pres = [i - 1 for i in map(int, input().split())]
level = [0] * n
from collections import deque

def bfs(v):
	q = deque([v])
	while q:
		v = q.pop()
		if cp[v] >= 0:
			level[v] = level[cp[v]] + 1
		for nv in adj[v]:
			q.append(nv)
for i in range(n):
	if cp[i] == -1:
		bfs(i)
for i in range(n):
	if level[i] > 0:
		par = cp[i]
		if pres[i] != pres[par] and level[pres[i]] <= level[par]:
			print(-1)
			return
pres = list(set(pres))
pres = sorted(pres, key=lambda i: level[i], reverse=True)
print(len(pres))
pres = [i + 1 for i in pres]
print('\n'.join(map(str, pres)))


import os, sys
from io import BytesIO, IOBase

def main():
	(n, m) = map(int, input().split())
	path = [[] for _ in range(n)]
	indeg = [0] * n
	for _ in range(m):
		(p1, q1) = map(int, input().split())
		path[p1 - 1].append(q1 - 1)
		indeg[q1 - 1] += 1
	gif = list(map(int, input().split()))
	(fin, poi) = ([], [0] * n)
	for i in range(n):
		if indeg[i]:
			continue
		(st, st1) = ([i], [i])
		while len(st):
			(x, y) = (st[-1], poi[st[-1]])
			if y == len(path[x]):
				st.pop()
				continue
			z = path[x][y]
			if gif[z] == z + 1:
				st1.append(z)
			elif gif[z] != gif[x]:
				print(-1)
				return
			st.append(z)
			poi[x] += 1
		fin += list(map(lambda xx: xx + 1, st1[::-1]))
	print(len(fin))
	print(*fin, sep='\n')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()