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.BigInteger;

public class A {

	static BufferedReader br;
	static PrintWriter pw;
	static int inf = (int) 1e9;
	static long mod = (long) 1e9 + 7;

	static String ans;

	static int n, k;

	static ArrayList<Integer> primes;
	static int[] isComposite;

	static void sieve(int N) // O(N log log N)
	{
		isComposite = new int[N + 1];
		isComposite[0] = isComposite[1] = 1; // 0 indicates a prime number
		primes = new ArrayList<Integer>();

		for (int i = 2; i <= N; ++i) // can loop till i*i <= N if primes array is not needed O(N log log sqrt(N))
			if (isComposite[i] == 0) // can loop in 2 and odd integers for slightly better performance
			{
				primes.add(i);
				if (1l * i * i <= N)
					for (int j = i * i; j <= N; j += i) // j = i * 2 will not affect performance too much, may alter in
														// modified sieve
						isComposite[j] = 1;
			}
	}

	static ArrayList<Integer> primeFactors(int N) // O(sqrt(N) / ln sqrt(N))
	{
		ArrayList<Integer> factors = new ArrayList<Integer>(); // take abs(N) in case of -ve integers
		int idx = 0, p = primes.get(idx);

		while (p * p <= N) {
			while (N % p == 0) {
				factors.add(p);
				N /= p;
			}
			p = primes.get(++idx);
		}

		if (N != 1) // last prime factor may be > sqrt(N)
			factors.add(N); // for integers whose largest prime factor has a power of 1
		return factors;
	}

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(System.out);
		StringTokenizer st = new StringTokenizer(br.readLine());
		n = Integer.parseInt(st.nextToken());
		g = new ArrayList[n];
		for (int i = 0; i < g.length; i++) {
			g[i] = new ArrayList<>();
		}
		st = new StringTokenizer(br.readLine());
		for (int i = 1; i < g.length; i++) {
			int p = Integer.parseInt(st.nextToken()) - 1;
			g[p].add(i);
			g[i].add(p);
		}
		st = new StringTokenizer(br.readLine());
		v = new int[n];
		for (int i = 0; i < g.length; i++) {
			v[i] = Integer.parseInt(st.nextToken());
		}
		f = true;
		vis = new boolean[n];
		long ans = dfs(0, 0, 1);
		pw.println(f ? ans : -1);
		pw.flush();
		pw.close();

	}

	static boolean[] vis;
	static int[] q;
	static int[] v;
	static boolean f;
	static ArrayList<Integer>[] g;

	static long dfs(int node, long sum, int par) {
		vis[node] = true;
		if (par % 2 == 0) {
			if (g[node].size() == 1) {
				return 0;
			} else {
				long min = (int) 1e9;
				long s = 0;
				for (int x : g[node]) {
					if (!vis[x]) {
						min = Math.min(min, v[x] - sum);
					}
				}
//				System.out.println(min);	
				for (int x : g[node]) {
					if (!vis[x]) {
						f &= v[x] >= sum;
						s += dfs(x, sum + min, par + 1);
					}
				}
				return s + min;
			}
		} else {
			long s = v[node] - sum;
//			System.out.println(node + " " + s);
			f &= v[node] >= sum;
			for (int x : g[node]) {
				if (!vis[x])
					s += dfs(x, v[node], par + 1);
			}
			return s;
		}
	}

	static boolean valid(int x) {
		return x >= 0 && x < n;
	}

	static void permute(pair[] a, int msk, String s, int l, int c) {
		if (msk == (1 << n) - 1) {
			ans = s;
			return;
		}
		for (int i = 0; i < n; i++) {
			if (((msk >> i) & 1) == 0) {
				if (c == 0) {
					if (a[i].x == a[l].y)
						permute(a, msk | 1 << i, s + (i + 1) + "a", i, 0);
					if (a[i].y == a[l].y)
						permute(a, msk | 1 << i, s + (i + 1) + "b", i, 1);
				} else {
					if (a[i].x == a[l].x)
						permute(a, msk | 1 << i, s + (i + 1) + "a", i, 0);
					if (a[i].y == a[l].x)
						permute(a, msk | 1 << i, s + (i + 1) + "b", i, 1);
				}

			}
		}
	}

	static int x;
	static int maxCount;
	static List<Integer> adj[];

	// Sets maxCount as maximum distance
	// from node
	static void dfsUtil(int node, int count, boolean visited[], List<Integer> adj[]) {
		visited[node] = true;
		count++;

		List<Integer> l = adj[node];
		for (Integer i : l) {
			if (!visited[i]) {
				if (count >= maxCount) {
					maxCount = count;
					x = i;
				}
				dfsUtil(i, count, visited, adj);
			}
		}
	}

	// The function to do DFS traversal. It uses
	// recursive dfsUtil()
	static void dfs(int node, int n, List<Integer> adj[]) {
		boolean[] visited = new boolean[n + 1];
		int count = 0;

		// Mark all the vertices as not visited
		Arrays.fill(visited, false);

		// Increment count by 1 for visited node
		dfsUtil(node, count + 1, visited, adj);

	}

	// Returns diameter of binary tree represented
	// as adjacency list.
	static int diameter(ArrayList<Integer> adj[], int n) {
		maxCount = Integer.MIN_VALUE;

		/*
		 * DFS from a random node and then see farthest node X from it
		 */
		dfs(1, n, adj);

		/*
		 * DFS from X and check the farthest node from it
		 */
		dfs(x, n, adj);

		return maxCount;
	}

	static class Polygon {
		// Cases to handle: collinear points, polygons with n < 3

		static final double EPS = 1e-9;

		Point[] g; // first point = last point, counter-clockwise representation

		Polygon(Point[] o) {
			g = o;
		}

		double perimeter() {
			double sum = 0.0;
			for (int i = 0; i < g.length - 1; ++i)
				sum += g[i].dist(g[i + 1]);
			return sum;
		}

		double area() // clockwise/anti-clockwise check, for convex/concave polygons
		{
			double area = 0.0;
			for (int i = 0; i < g.length - 1; ++i)
				area += g[i].x * g[i + 1].y - g[i].y * g[i + 1].x;
			return Math.abs(area) / 2.0; // negative value in case of clockwise
		}

		public static Polygon convexHull(Point[] points) // all points are unique, remove duplicates, edit ccw to accept
		// collinear points
		{
			int n = points.length;
			Arrays.sort(points);
			Point[] ans = new Point[n << 1];
			int size = 0, start = 0;

			for (int i = 0; i < n; i++) {
				Point p = points[i];
				while (size - start >= 2 && !Point.ccw(ans[size - 2], ans[size - 1], p))
					--size;
				ans[size++] = p;
			}
			start = --size;

			for (int i = n - 1; i >= 0; i--) {
				Point p = points[i];
				while (size - start >= 2 && !Point.ccw(ans[size - 2], ans[size - 1], p))
					--size;
				ans[size++] = p;
			}
			// if(size < 0) size = 0 for empty set of points
			return new Polygon(Arrays.copyOf(ans, size));
		}
	}

	static class Point implements Comparable<Point> {

		static final double EPS = 1e-9;

		double x, y;

		Point(double a, double b) {
			x = a;
			y = b;
		}

		static double angle(Point a, Point o, Point b) // angle AOB
		{
			Vector oa = new Vector(o, a), ob = new Vector(o, b);
			return Math.acos(oa.dot(ob) / Math.sqrt(oa.norm2() * ob.norm2()));
		}

		public int compareTo(Point p) {
			if (Math.abs(x - p.x) > EPS)
				return x > p.x ? 1 : -1;
			if (Math.abs(y - p.y) > EPS)
				return y > p.y ? 1 : -1;
			return 0;
		}

		public double dist(Point p) {
			return Math.sqrt(sq(x - p.x) + sq(y - p.y));
		}

		static double sq(double x) {
			return x * x;
		}

		Point rotate(double angle) {
			double c = Math.cos(angle), s = Math.sin(angle);
			return new Point(x * c - y * s, x * s + y * c);
		}

		// for integer points and rotation by 90 (counterclockwise) : swap x and y,
		// negate x
		static boolean ccw(Point p, Point q, Point r) {
			return new Vector(p, q).cross(new Vector(p, r)) > 0;
		}

		static double distToLine(Point p, Point a, Point b) // distance between point p and a line defined by points a,
															// b (a != b)
		{
			if (a.compareTo(b) == 0)
				return p.dist(a);
			// formula: c = a + u * ab
			Vector ap = new Vector(a, p), ab = new Vector(a, b);
			double u = ap.dot(ab) / ab.norm2();
			Point c = a.translate(ab.scale(u));
			return p.dist(c);
		}

		Point translate(Vector v) {
			return new Point(x + v.x, y + v.y);
		}

	}

	static class Vector {

		double x, y;

		Vector(double a, double b) {
			x = a;
			y = b;
		}

		Vector(Point a, Point b) {
			this(b.x - a.x, b.y - a.y);
		}

		Vector scale(double s) {
			return new Vector(x * s, y * s);
		} // s is a non-negative value

		double dot(Vector v) {
			return (x * v.x + y * v.y);
		}

		double cross(Vector v) {
			return x * v.y - y * v.x;
		}

		double norm2() {
			return x * x + y * y;
		}

		Vector reverse() {
			return new Vector(-x, -y);
		}

		Vector normalize() {
			double d = Math.sqrt(norm2());
			return scale(1 / d);
		}
	}

	static class pair implements Comparable<pair> {
		int x;
		int y;

		public pair(int d, int u) {
			x = d;
			y = u;
		}

		public int compareTo(pair o) {
			return y - o.y;
		}

	}

	static class triple implements Comparable<triple> {
		int x;
		int y;
		int z;

		public triple(int a, int b, int c) {
			x = a;
			y = b;
			z = c;
		}

		public int compareTo(triple o) {
			return x - o.x;
		}
	}

	static int[] nxtarr() throws IOException {
		StringTokenizer st = new StringTokenizer(br.readLine());
		int[] a = new int[st.countTokens()];
		for (int i = 0; i < a.length; i++) {
			a[i] = Integer.parseInt(st.nextToken());
		}
		return a;
	}

	static long pow(long a, long e) // O(log e)
	{
		long res = 1;
		while (e > 0) {
			if ((e & 1) == 1)
				res *= a;
			a *= a;
			e >>= 1;
		}
		return res;
	}

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