Mitya has a rooted tree with n vertices indexed from 1 to n, where the root has index 1. Each vertex v initially had an integer number a_v ≥ 0 written on it. For every vertex v Mitya has computed s_v: the sum of all values written on the vertices on the path from vertex v to the root, as well as h_v — the depth of vertex v, which denotes the number of vertices on the path from vertex v to the root. Clearly, s_1=a_1 and h_1=1.

Then Mitya erased all numbers a_v, and by accident he also erased all values s_v for vertices with even depth (vertices with even h_v). Your task is to restore the values a_v for every vertex, or determine that Mitya made a mistake. In case there are multiple ways to restore the values, you're required to find one which minimizes the total sum of values a_v for all vertices in the tree.

Input

The first line contains one integer n — the number of vertices in the tree (2 ≤ n ≤ 10^5). The following line contains integers p_2, p_3, ... p_n, where p_i stands for the parent of vertex with index i in the tree (1 ≤ p_i < i). The last line contains integer values s_1, s_2, ..., s_n (-1 ≤ s_v ≤ 10^9), where erased values are replaced by -1.

Output

Output one integer — the minimum total sum of all values a_v in the original tree, or -1 if such tree does not exist.

Examples

Input


5
1 1 1 1
1 -1 -1 -1 -1


Output


1


Input


5
1 2 3 1
1 -1 2 -1 -1


Output


2


Input


3
1 2
2 -1 1


Output


-1
import math,sys,bisect,heapq,os
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate
from functools import lru_cache
sys.setrecursionlimit(200000000)
int1 = lambda x: int(x) - 1
def input(): return sys.stdin.readline().rstrip('\r\n')
#input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
aj = lambda: list(map(int, input().split()))
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
#MOD = 1000000000 + 7
def Y(c):  print(["NO","YES"][c])
def y(c):  print(["no","yes"][c])
def Yy(c):  print(["No","Yes"][c])



def solve():
	G = defaultdict(list)

	def addEdge(a,b):
		G[a].append(b)
		#G[b].append(a)

	n, = aj()
	p = aj()
	p = [-1] + p
	s = aj()
	if -1 not in s:
		print(sum(s))
		exit(0)

	if s.count(0) + s.count(-1) == n:
		print(0)
		exit(0)

	mark = {}
	for i in range(n):
		if s[i] != -1:
			mark[i+1] = s[i]

	#recursive dfs
	'''
	def dfs(node):
		for c in G.get(node,[]):
			dfs(c)
			if s[node-1] > mark.get(c,float('inf')):
				print(-1)
				exit(0)
			mark[node] = min(mark.get(node,float('inf')),mark.get(c,float('inf')))
	'''

	def ddfs(node):
		st = deque()
		st.append(node)
		order = []
		while st:
			x = st.pop()
			order.append(x)
			for c in G.get(x,[]):
				st.append(c)
		for z in range(n-1, -1, -1):
			v = order[z]
			for nv in G.get(v,[]):
				if nv != p[v-1]:
					if s[v-1] > mark.get(nv,float('inf')):
						print(-1)
						exit(0)
					mark[v] = min(mark.get(nv,float('inf')),mark.get(v,float('inf')))

		

	
	for ii,i in enumerate(p):
		addEdge(i,ii+1)

	# print(G)

	ddfs(1)
	#print(mark)
	ans = mark[1]
	for ii,i in enumerate(p):
		#print(ii+1,i)
		if ii == 0:
			continue
		if mark.get(ii+1,float('inf')) != float('inf') and mark.get(i,float('inf')) != float('inf'):
			ans += abs(mark[ii+1] - mark[i])
			#print(ii+1,i)
	print(ans)




try:
	#os.system("online_judge.py")
	sys.stdin = open('input.txt', 'r') 
	sys.stdout = open('output.txt', 'w')
except:
	pass

solve()