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 java.util.*;

import java.io.*;
import java.math.*;
import java.awt.geom.*;

import static java.lang.Math.*;

public class Solution implements Runnable {

	long mod1 = (long) 1e9 + 7;
	int mod2 = 998244353;
	int arr[];
	int sum[];

	public void solve() throws Exception {
		int n=sc.nextInt();
		arr=new int[n+1];
		arr[0]=1;
		sum=new int[n+1];
		sum[0]=1;
		Node nodes[]=new Node[n];
		nodes[0]=new Node(0,-1,new ArrayList<>());
		for(int i=1;i<n;i++) {
			nodes[i]=new Node(i,sc.nextInt()-1,new ArrayList<>());
		}
		sum[0]=sc.nextInt();
		arr[0]=sum[0];
		for(int i=1;i<n;i++) {
			nodes[nodes[i].parent].children.add(i);
			sum[i]=sc.nextInt();
			
		}
		for(int i=0;i<n;i++) {
			//out.println(nodes[i]);
		}
		boolean flag=true;
		for(int i=0;i<n;i++) {
			if(sum[i]!=-1) {
				if(i!=0) {
					arr[i]=sum[i]-sum[nodes[i].parent];
				}
			}
			else {
				int min=Integer.MAX_VALUE;
				for(int ii:nodes[i].children) {
					min=Math.min(min,sum[ii]);
				}
				if(min!=Integer.MAX_VALUE && min<sum[nodes[i].parent]) {
					flag=false;
				}
				//out.println(min+" "+sum[nodes[i].parent]);
				if(min==Integer.MAX_VALUE) {
					min=sum[nodes[i].parent];
				}
				sum[i]=min;
				arr[i]=sum[i]-sum[nodes[i].parent];
			}
		}
		long s=0;
		if(!flag) {
			out.println(-1);
			return;
		}
		for(int i:arr) {
			//out.println(i);
			s+=i;

		}
		out.println(s);
		
		
		

	}
	
	
	class Node {
		int index;
		int parent;
		ArrayList<Integer> children;
		public Node(int index, int parent, ArrayList<Integer> children) {
			super();
			this.index = index;
			this.parent = parent;
			this.children = children;
		}
		@Override
		public String toString() {
			return "Node [index=" + index + ", parent=" + parent + ", children=" + children + "]";
		}
		
		
	}

	static void sort(int[] a) {
		ArrayList<Integer> l = new ArrayList<>();
		for (int i : a)
			l.add(i);
		Collections.sort(l);
		for (int i = 0; i < a.length; i++)
			a[i] = l.get(i);
	}

	static long gcd(long a, long b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}

	static long ncr(int n, int r, long p) {
		if (r > n)
			return 0l;
		if (r > n - r)
			r = n - r;

		long C[] = new long[r + 1];

		C[0] = 1;

		for (int i = 1; i <= n; i++) {

			for (int j = Math.min(i, r); j > 0; j--)
				C[j] = (C[j] + C[j - 1]) % p;
		}
		return C[r] % p;
	}

	public long power(long x, long y, long p) {
		long res = 1;
		// out.println(x+" "+y);
		x = x % p;
		if (x == 0)
			return 0;

		while (y > 0) {
			if ((y & 1) == 1)
				res = (res * x) % p;
			y = y >> 1;
			x = (x * x) % p;
		}
		return res;
	}

	static Throwable uncaught;

	BufferedReader in;
	FastScanner sc;
	PrintWriter out;

	@Override
	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			sc = new FastScanner(in);
			solve();
		} catch (Throwable uncaught) {
			Solution.uncaught = uncaught;
		} finally {
			out.close();
		}
	}

	public static void main(String[] args) throws Throwable {
		Thread thread = new Thread(null, new Solution(), "", (1 << 26));
		thread.start();
		thread.join();
		if (Solution.uncaught != null) {
			throw Solution.uncaught;
		}
	}

}

class FastScanner {

	BufferedReader in;
	StringTokenizer st;

	public FastScanner(BufferedReader in) {
		this.in = in;
	}

	public String nextToken() throws Exception {
		while (st == null || !st.hasMoreTokens()) {
			st = new StringTokenizer(in.readLine());
		}
		return st.nextToken();
	}

	public int nextInt() throws Exception {
		return Integer.parseInt(nextToken());
	}

	public int[] readArray(int n) throws Exception {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long nextLong() throws Exception {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws Exception {
		return Double.parseDouble(nextToken());
	}

}