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.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;

@SuppressWarnings("unchecked")
public class A {
	
	int n;
	long[] s;
	long[] a;
	ArrayList<Integer>[] vs;
	int[] p;
	
	boolean go(int node, int par) {
		if(s[node] == -1 && vs[node].isEmpty()) {
			a[node] = 0;
			s[node] = par == -1 ? 0 : s[par];
			return true;
		}
		if(s[node] == -1) {
			long minChildSum = Long.MAX_VALUE;
			for(int i : vs[node]) minChildSum = Math.min(minChildSum, s[i]);
			long me = minChildSum - s[par];
			a[node] = me;
			s[node] = s[par] + me;
			if(me < 0) return false;
		} else if(par != -1) {
			a[node] = s[node] - s[par];
			if(a[node] < 0) return false;
		}
//		if(par != -1 && s[par] == -1) {
//			long minChildSum = Integer.MAX_VALUE;
//			for(int i : vs[node]) minChildSum = Math.min(minChildSum, s[i]);
//			
//			if(a[par] == -1) {
//				a[par] = s[node] - s[p[par]];
//				if(a[par] < 0) return false;
//			} else {
//				long wanted = s[node] - s[p[par]];
//				if(a[par] != wanted) return false;
//			}
//		}
		boolean ret = true;
		for(int i : vs[node]) ret &= go(i, node);
		return ret;
	}
	
//	boolean go2(int node, int par) {
//		if(a[node] == -1) {
//			a[node] = s[node] - (s[p[par]] + a[par]);
//			if(a[node] < 0) return false;
//		}
//		boolean ret = true;
//		for(int i : vs[node]) ret &= go2(i, node);
//		return ret;
//	}
	
	public void solve(JS in, PrintWriter out) {
		n = in.nextInt();
		vs = new ArrayList[n];
		s = new long[n];
		a = new long[n];
		p = new int[n];
		Arrays.fill(p, -1);
		Arrays.fill(a, -1);
		for(int i = 0; i < n; ++i) vs[i] = new ArrayList<Integer>();
		for(int i = 1; i < n; ++i) {
			int pp = in.nextInt() - 1;
			vs[pp].add(i);
			p[i] = pp;
		}
		for(int i = 0; i < n; ++i) s[i] = in.nextInt();
		a[0] = s[0];
		
		boolean possible = go(0, -1);
		if(!possible) out.println(-1);
		else {
//			possible &= go2(0, -1);
//			if(!possible) out.println(-1);
//			else {
				long sum = 0;
				for(int i = 0; i < n; ++i) sum += a[i];
				out.println(sum);
//			}
		}
	}
	
	public static void main(String[] args) {
		JS in = new JS();
		PrintWriter out = new PrintWriter(System.out);
		new A().solve(in, out);
		out.close();
	}
	
	static class JS {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public JS() {
			in = new BufferedInputStream(System.in, BS);
		}

		public JS(String s) throws FileNotFoundException {
			in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
	}
}
