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
//package com.company;
import java.io.*;
import java.util.*;
public class Main
{
	public static void main(String args[])
	{
		new Main().run();
	}
	public long sum(int a[])
	{	long sum=0;
		for (int i=0;i<a.length;i++) {
			sum += a[i];
			//writer.println(a[i]);
		}
		return sum;
	}
	public void solve()throws IOException
	{
		int n=nextInt();
		//long m=nextLong();
		Graph g=new Graph(n);
		int a[]=new int[n];
		for (int i=1;i<n;i++)
		{
			a[i]=nextInt();
			g.addEdge(i,a[i]-1);
		}
		int b[]=new int[n];
		for (int i=0;i<n;i++)
		{
			b[i]=nextInt();
			//g.addEdge(i,a[i]-1);
		}
		g.DFSUtil(0,b,0);
		boolean e=g.DFS(0,b,0);
		//int t[]=new int[n];
		int[] t=g.ret;
		//writer.println(e);
		//for(int i=0;i<n;i++)
			//writer.println(b[i]);
		if (!e)
			writer.println(-1);
		else
			writer.println(sum(t));

	}

	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;

	public void run() {
		try {
			reader = new BufferedReader(new InputStreamReader(System.in));
			tokenizer = null;
			writer = new PrintWriter(System.out);
			solve();
			reader.close();
			writer.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

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

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

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

	String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
}
class Graph
{
	private int V;
	private LinkedList<Integer> adj[];
	private boolean visited[];
	private boolean visited1[];
	int ret[];
	int res=0;
	Graph(int v)
	{
		V = v;
		visited = new boolean[V];
		visited1 = new boolean[V];
		ret = new int[V];
		adj = new LinkedList[v];
		for (int i=0; i<v; i++)
		{   adj[i] = new LinkedList();
		}
	}

	void addEdge(int v, int w)
	{
		adj[v].add(w);
		adj[w].add(v);// Add w to v's list.
	}

	int DFSUtil(int v,int dep[],int last)
	{
		visited[v] = true;
		//System.out.println(v);
		if (dep[v]!=-1)
			last=dep[v];
		int s=-1;
		Iterator<Integer> i = adj[v].listIterator();
		while (i.hasNext())
		{
			int n = i.next();
			if (!visited[n])
			{
				//System.out.println(dep[n]+" "+n);
				if(s==-1) {
					s = DFSUtil(n, dep,last);
				}
				else
					s = Math.min(s, DFSUtil(n, dep,last));

			}
		}
		if(s==-1)
			s=last;
		if (dep[v]==-1)
			dep[v]=Math.max(s,0);
		//System.out.println(last+" "+dep[v]+" "+v);
		return dep[v];
	}

	boolean DFS(int v,int dep[],int prev)
	{
		visited1[v]=true;
		ret[v]=dep[v]-prev;
		//System.out.println(dep[v]+" "+prev+" "+v);
		if (ret[v]<0)
			return false;
		boolean r=true;
		Iterator<Integer> i = adj[v].listIterator();
		while (i.hasNext())
		{
			int n = i.next();
			if (!visited1[n])
			{
				//System.out.println(dep[n]+" "+n);
				r=DFS(n, dep, dep[v]);
				if (r==false)
					return false;
			}

		}
		return r;
	}


}