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

public class Main
{
	static class Graph{
		int h[],V,deg[],s[],a[],par[];
		ArrayList l[];
		boolean visited[];

		public Graph(int v){
			V=v;
			l=new ArrayList[V+1];
			visited=new boolean[V+1];
			h=new int[V+1];
			deg=new int[V+1];
			s=new int[V+1];
			a=new int[V+1];
			par=new int[V+1];

			h[1]=1;

			for(int i=0;i<=V;i++){
				l[i]=new ArrayList<Integer>();
				visited[i]=false;
			}
		}

		void addEdge(int u,int v){
			l[u].add(v);
			l[v].add(u);

			deg[u]++;deg[v]++;

			par[u]=v;
		}

		void dfs(int node){
			visited[node]=true;
			ArrayList<Integer> x=l[node];

			for(Integer child : x){
				if(visited[child])
					continue;
				h[child]=1+h[node];

				dfs(child);
			}
		}

		void res(){
			Arrays.fill(visited,false);
			dfs_2(1,0);

			long res=0l;
			for(int i=2;i<=V;i++){
				// if(deg[i]==1)
				// 	continue;
				a[i]=s[i]-s[par[i]];
			}

			for(int i=1;i<=V;i++){
				if(a[i]<0){
					pn(-1);
					return;
				}
				res+=a[i];
			}
			pn(res);
		}

		void dfs_2(int node,int par){
			visited[node]=true;
			ArrayList<Integer> x = l[node];

			if(deg[node]==1 && s[node]==-1){
				//pn(node);
				s[node]=s[par];
				a[node]=0;
				return;
			}

			int choose_sum=Integer.MAX_VALUE;

			for(Integer child : x){
				if(visited[child])
					continue;
				if(s[node]==-1){
					choose_sum=Math.min(choose_sum,s[child]-s[par]);
					//pn(choose_sum+" when "+s[child]+" "+s[par]);
				}
			}

			if(s[node]==-1){
				// if(node==2){
				// 	pn(s[par]+" "+choose_sum);
				// }
				s[node]=choose_sum+s[par];
				//pn(s[node]);
			}

			for(Integer child : x){
				//pn("dfs");
				if(visited[child])
					continue;
				//pn("fdafds"+child);
				dfs_2(child,node);
			}
		}
	}
    public static void process()throws IOException
    {
    	int n=ni();
    	Graph g = new Graph(n);

    	for(int i=2;i<=n;i++) g.addEdge(i,ni());

    	for(int i=1;i<=n;i++) g.s[i]=ni();

    	g.a[1]=g.s[1];

    	g.dfs(1);
    	g.res();//pn(Arrays.toString(g.a));
    }


   	static AnotherReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        out = new PrintWriter(System.out);
        sc=new AnotherReader();
        boolean oj = true;

    	oj = System.getProperty("ONLINE_JUDGE") != null;
    	if(!oj) sc=new AnotherReader(100);

        long s = System.currentTimeMillis();
        int t=1;
        while(t-->0)
            process();
        out.flush();
        if(!oj)
            System.out.println(System.currentTimeMillis()-s+"ms");
        System.out.close();  
    }

    static void pn(Object o){out.println(o);}
    static void p(Object o){out.print(o);}
    static void pni(Object o){out.println(o);System.out.flush();}
    static int ni()throws IOException{return sc.nextInt();}
    static long nl()throws IOException{return sc.nextLong();}
    static double nd()throws IOException{return sc.nextDouble();}
    static String nln()throws IOException{return sc.nextLine();}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
    static boolean multipleTC=false;



/////////////////////////////////////////////////////////////////////////////////////////////////////////

    static class AnotherReader{BufferedReader br; StringTokenizer st;
    AnotherReader()throws FileNotFoundException{
    br=new BufferedReader(new InputStreamReader(System.in));}
    AnotherReader(int a)throws FileNotFoundException{
    br = new BufferedReader(new FileReader("input.txt"));}
    String next()throws IOException{
    while (st == null || !st.hasMoreElements()) {try{
    st = new StringTokenizer(br.readLine());}
    catch (IOException  e){ e.printStackTrace(); }}
    return st.nextToken(); } int nextInt() throws IOException{
    return Integer.parseInt(next());}
    long nextLong() throws IOException
    {return Long.parseLong(next());}
    double nextDouble()throws IOException { return Double.parseDouble(next()); }
    String nextLine() throws IOException{ String str = ""; try{
    str = br.readLine();} catch (IOException e){
    e.printStackTrace();} return str;}}
    
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
	
	
	