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

public class asitis
{
	static long inf=(long)Double.POSITIVE_INFINITY;
	static class node1
	{
		int data;
		node1 link=null;
		node1(int d)
		{
			data=d;
		}
	}
	static class linkl
	{
		node1 front=null,end=null;

		void inst(int d)
		{
			node1 newnode=new node1(d);
			if(front==null){front=newnode;end=newnode;}
			else
			{
				end.link=newnode;end=newnode;
			}
		}
	}
	static class node_4graph
	{
		long av=-1,sv=-1;linkl l;
		node_4graph()
		{
			l=new linkl();
		}
	}
	static class graph
	{
		node_4graph[] arr;int[] vis;
		graph(int n)
		{
			arr=new node_4graph[n];
			for(int i=0;i<n;i++)
			{
				node_4graph lw=new node_4graph();
				arr[i]=lw;
			}
			vis=new int[n];
		}
		void insert(int x,int y)
		{
			arr[x].l.inst(y);
		}
		void DFS(int u,long pehle)
		{
			vis[u]=1;
			long svv=inf;

			node1 temp=arr[u].l.front;

			if(arr[u].sv==-1)
			{
				while(temp!=null)
				{
					svv=Math.min(svv,arr[temp.data].sv);
					if(vis[temp.data]==0)
						DFS(temp.data,0);
					temp=temp.link;
				}
				if(svv==inf)
					arr[u].sv=pehle;
				else
					arr[u].sv=svv;
			}
			else
			{
				while(temp!=null)
				{
					if(vis[temp.data]==0)
						DFS(temp.data,arr[u].sv);
					temp=temp.link;
				}
			}
		}
		void DFS2(int u,long pehle)
		{
			vis[u]=1;
			arr[u].av=arr[u].sv-pehle;
			node1 temp=arr[u].l.front;
			while(temp!=null)
			{
				if(vis[temp.data]==0)
					DFS2(temp.data,arr[u].sv);
				temp=temp.link;
			}
		}

	}

	
	static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));	

	
	
	
	public static void main(String[] args)throws IOException{
		

		int n=Integer.parseInt(br.readLine());
		String[] s=br.readLine().split(" ");
		String[] s1=br.readLine().split(" ");

		graph gr=new graph(n+1);
		for(int i=0;i<n-1;i++)
		{
			int hh=Integer.parseInt(s[i]);
			gr.insert(hh,i+2);
		}

		for(int i=0;i<n;i++)
		{
			gr.arr[i+1].sv=Long.parseLong(s1[i]);
		}
		gr.arr[1].av=gr.arr[1].sv;
		gr.DFS(1,0);

		gr.vis=new int[n+1];
		gr.DFS2(1,0);
		long sum=0;
		for(int i=1;i<=n;i++)
		{
			sum+=gr.arr[i].av;
			if(gr.arr[i].av<0)
			{
				System.out.println(-1);
				System.exit(0);
			}
		}
		System.out.println(sum);

	}
	
}