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.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map.Entry;

import java.util.Random;
import java.util.Scanner;
import java.util.TreeSet;

public final class CF_530_D2_D {


	static boolean verb=true;
	static void log(Object X){if (verb) System.err.println(X);}
	static void log(Object[] X){if (verb) {for (Object U:X) System.err.print(U+" ");System.err.println("");}}
	static void log(int[] X){if (verb) {for (int U:X) System.err.print(U+" ");System.err.println("");}}
	static void log(int[] X,int L){if (verb) {for (int i=0;i<L;i++) System.err.print(X[i]+" ");System.err.println("");}}
	static void log(long[] X){if (verb) {for (long U:X) System.err.print(U+" ");System.err.println("");}}

	static void logWln(Object X){if (verb) System.err.print(X);}
	static void info(Object o){	System.out.println(o);}
	static void output(Object o){outputWln(""+o+"\n");	}
	static void outputWln(Object o){try {out.write(""+ o);} catch (Exception e) {}}

	//static long mod=1000000007;
	static long mod=998244353 ; 
	static int CX=64;


	// Global vars
	static BufferedWriter out;
	static InputReader reader;


	static void process() throws Exception {

		Locale.setDefault(Locale.US);
		out = new BufferedWriter(new OutputStreamWriter(System.out));
		reader = new InputReader(System.in);

		int n=reader.readInt();

		int[] anc=new int[n];

		int[] f=new int[n];
		for (int i=1;i<n;i++) {
			anc[i]=reader.readInt()-1;
			f[anc[i]]++;
		}
		anc[0]=-1;

		int[][] friends=new int[n][];
		for (int u=0;u<n;u++)
			friends[u]=new int[f[u]];

		for (int u=1;u<n;u++) {
			int v=anc[u];
			friends[v][--f[v]]=u;
		}

		int MX=Integer.MAX_VALUE;
		int[] s=new int[n];


		for (int i=0;i<n;i++) {
			s[i]=reader.readInt();

		}
		log("s done");

		int[] a=new int[n];

		int[] stack=new int[n];
		int[] h=new int[n];
		int st=0;
		stack[st++]=0;
		boolean ok=true;
		while (st>0) {
			int u=stack[st-1];
			st--;
			//log("u:"+(u+1));
			boolean X=h[u]%2==0;
			boolean Y=s[u]>=0;
			if (X!=Y) {

				ok=false;
				break;
			}
			for (int v:friends[u]) {
				stack[st++]=v;
				h[v]=h[u]+1;
			}

		}

		log("check done");


		a[0]=s[0];

		if (ok) {
			int rd=0,wr=0;
			stack[wr++]=0;

			loop:while (rd<wr) {
				int u=stack[rd++];
				int pos=0;
				int neg=0;
				int min=MX;
				if (h[u]%2==0) 
					for (int v:friends[u]) {
						stack[wr++]=v;
					} else

						for (int v:friends[u]) {
							stack[wr++]=v;
							if (min>s[v])
								min=s[v];
						}

				if (h[u]%2==0) {
					if (u>0) {
						int v=anc[u];
						a[u]=s[u]-s[v];
					}
				} else {
					if (friends[u].length==0)
						a[u]=0;
					else {
						int v=anc[u];
						if (s[v]>min) {
							ok=false;
							break loop;
						}
						a[u]=min-s[v];
						s[u]=min;
					}
				}
			}

		}
		long ans=-1;
		if (ok) {
			ans=0;
			for (int u=0;u<n;u++)
				ans+=a[u];
		}
		output(ans);

		try {
			out.close();
		} catch (Exception E) {
		}

	}

	public static void main(String[] args) throws Exception {
		process();

	}

	static final class InputReader {
		private final InputStream stream;
		private final byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		private int read() throws IOException {
			if (curChar >= numChars) {
				curChar = 0;
				numChars = stream.read(buf);
				if (numChars <= 0) {
					return -1;
				}
			}
			return buf[curChar++];
		}

		public final String readString() throws IOException {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.append((char) c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public final int readInt() throws IOException {
			int c = read();
			boolean neg = false;
			while (isSpaceChar(c)) {
				c = read();
			}
			char d = (char) c;
			// log("d:"+d);
			if (d == '-') {
				neg = true;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			// log("res:"+res);
			if (neg)
				return -res;
			return res;

		}

		public final long readLong() throws IOException {
			int c = read();
			boolean neg = false;
			while (isSpaceChar(c)) {
				c = read();
			}
			char d = (char) c;
			// log("d:"+d);
			if (d == '-') {
				neg = true;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			// log("res:"+res);
			if (neg)
				return -res;
			return res;

		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
	}

}