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
from fractions import gcd
from math import factorial, ceil, sqrt, atan2, log, pi, e, asin,acos, cos, sin, floor, atan
from itertools import *
from fractions import Fraction
import string
import copy
import random
import bisect
from decimal import *
from collections import deque
from sys import *
digs = string.digits + string.ascii_letters

def id_generator(size=20, chars=string.digits):
    return ''.join(random.choice(chars) for _ in range(size))
 
def mp():
    return map(int,str(raw_input()).strip().split())

mod=10**9+7

n=input()
l=list(mp())
z=list(mp())
tree=[[] for i in range(n+1)]

val=[0 for i in range(n+1)]

for i in range(n-1):
	x=l[i]
	tree[x]+=[i+2]


q=[1]
i=0
j=1
while i<j:
	node=q[i]
	# print node,q,i,j
	if z[node-1]!=-1 and val[node]==0:
		if node==1:
			val[node]=z[node-1]
		else:
			val[node]=z[node-1]-z[l[l[node-2]-2]-1]
	for k in range(len(tree[node])):
		q+=[tree[node][k]]
		j+=1
	i+=1

for i in val:
	if i<0:
		print -1
		exit()

# print val
for i in range(1,n+1):
	if z[i-1]!=-1:
		# print z,val,z[i-1],val[i],i
		z[i-1]=val[i]

val=[10**18 for i in range(n+1)]
for i in range(n-1):
	x=l[i]
	if z[i+1]!=-1:
		val[x]=min(val[x],z[i+1])

for i in range(n-1):
	x=l[i]
	if z[i+1]!=-1:
		z[i+1]-=val[x]

# print val,z
for i in range(n+1):
	if val[i]==10**18:
		val[i]=0
		
for i in range(n):
	if z[i]!=-1:
		val[i+1]+=z[i]


# print val,z,tree
# q=[1]
# i=0
# j=1
# while i<j:
# 	node=q[i]
# 	# print node,q,i,j
# 	if z[node-1]!=-1 and val[node]==0:
# 		if node==1:
# 			val[node]=z[node-1]
# 		else:
# 			val[node]=z[node-1]-z[l[l[node-2]-2]-1]
# 	for k in range(len(tree[node])):
# 		q+=[tree[node][k]]
# 		j+=1
# 	i+=1

# for i in val:
# 	if i<0:
# 		print -1
# 		exit()

print sum(val)