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 test {
	static long sum=0l;//-10000000000l;
	static boolean boo =  true;
	public static long G(int x,List<List<Integer>> list,int[] v,long[] min,long up)
   {
   	   long m = 2000000000l;
   	   if(v[x] != -1) {m = v[x]+0l;}
       
       for(int y : list.get(x))
       {
       	   m=Math.min(m,G(y,list,v,min,v[x]+0l));
       }
       min[x] = m;
       if(m<up) boo=false;
       return m;
       
   }
   public static void F(int x,List<List<Integer>> list,long s,int[] v,long[] min)
   {
   	   //if(sum==-1l) return false;
   	   
   	   if(v[x] != -1)
   	   {
   	   	   if((v[x]+0l) >= s)
   	   	   {
   	   	   	  sum += (v[x]-s);
   	   	   }
   	   	   else{
   	   	   	boo=false;return;
   	   	   }
   	   	   s=v[x]+0l;
   	   	   for(int y : list.get(x))
	       {
	       	   F(y,list,s,v,min);
	       	   
	       }
   	   	
   	   }
   	   else
   	   {
   	   		long mi = min[x];
            if(mi == 2000000000l) return;
   	   		if(mi < s)
   	   		{
   	   			 boo=false;return;
   	   		}
   	   		else
   	   		{
   	   			sum += (mi-s);
   	   		}
   	   		s=mi;
   	   		for(int y : list.get(x))
	    	{
	       	   F(y,list,s,v,min);
	       	   
	    	}
   	   }
   	   
       
   }
   public static String print(Object o)
   {
   	 return o.toString();
   }
	public static void main (String[] args) throws Exception {
        
		BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
        
		int y=1;//Integer.parseInt(bf.readLine());
		for(int h=0;h<y;h++)
		{
		    String[] xl=(bf.readLine()).split(" ");int i=0;
            int a,b,m,n;long ans=0l;
            n=Integer.parseInt(xl[0]);
            //a=Integer.parseInt(xl[1])-1;
            //b=Integer.parseInt(xl[2])-1;
            List<List<Integer>> lis=new ArrayList<>();
            for(int o=0;o<n;o++) lis.add(new ArrayList<>());
          xl=bf.readLine().split(" ");
            for(int o=0;o<n-1;o++)
                {
                
                	
                	int q,w;
                	q=Integer.parseInt(xl[o]);
                	//w=Integer.parseInt(xl[1]);
                	lis.get(q-1).add(o+1);//lis.get(w+1).add(q-1);
                }
            int[] val=new int[n];
            
			xl=bf.readLine().split(" ");
			
			for(int o=0;o<n;o++)
			{
				val[o]=Integer.parseInt(xl[o]);
				
			}
			long[] min=new long[n];
			G(0,lis,val,min,0l);
			//boolean bol = F(0,lis,0l,val);
            //System.out.println(bol);
            if(!boo)
            {
            	System.out.println("-1");return;
            }
           F(0,lis,0l,val,min);
			if(boo) System.out.println(sum);
			else System.out.println(-1);
                
            


                
            }
            
            
            
		}
	}



