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
	/*
	TO LEARN
	1-segment trees
	2-euler tour
	3-fenwick tree and interval tree
	*/
	/*
	TO SOLVE 
	uva 1103
	program codeforces edu 102 D
	*/
	/*
	bit manipulation shit
	1-Computer Systems: A Programmer's Perspective
	2-hacker's delight
	3-(02-03-bits-ints)
	4-machine-basics
	5-Bits Manipulation tutorialspoint
	*/
	/*
	TO WATCH
	1-what is bitmasking by kartik arora youtube

	*/
	            import java.util.*;
			    import java.math.*;
			    import java.io.*; 
			    import java.util.stream.Collectors;

			       public class A{
			     
			  static InputStream inputStream = System.in;
	            static FastScanner scan=new FastScanner();
			     public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	static boolean vis[]=new boolean[(int)1e5+5];
	static LinkedList<Integer>edges[];
	static int s[];
	static void dfs(int x,int min,int dep)
	{
		Set<Integer>set=new HashSet<Integer>();
		int cnt=0;
		//System.out.println(x);
		if(s[x]!=-1&&s[x]<min)
		{
			//System.out.println("FUCK");
			System.out.println(-1);
			System.exit(0);
		}
		/*for(int v:edges[x])
		{
			if(!vis[v])
			{
				set.add(s[v]);
				cnt++;
			}
		}
		if(set.size()>1&&dep%2==0)
		{
			System.out.println(x+" "+dep);
			System.out.println(-1);
			System.exit(0);
		}*/
		vis[x]=true;
		for(int v:edges[x])
		{
			//System.out.println("V "+v);
			if(!vis[v])
			{
				//System.out.println("FUCK");
				dfs(v,Math.max(s[x],min),dep+1);
			}
		}
	}
	static int res[];
	static void dfs1(int x,int dep)
	{
		if(dep%2==0)
		{
			s[x]=Integer.MAX_VALUE;

			if(edges[x].size()==1)
				s[x]=-1;

			for(int v:edges[x])
			{
				if(!vis[v])
				s[x]=Math.min(s[x],s[v]);
			}
			//System.out.println("ED "+x+" "+edges[x].size()+" "+s[x]);
			/*for(int v:edges[x])
			{
				if(!vis[v])
				res[v]=s[v]-res[x];
			}*/
		}
		vis[x]=true;
		for(int v:edges[x])
		{
			if(!vis[v])
				dfs1(v,dep+1);
		}
	}
	static void dfs2(int x,int dep,int sum)
	{
		vis[x]=true;
	// System.out.println(sum+" "+s[x]+" "+x);
		if(s[x]!=-1){
		if(x==0)
			res[x]=s[x];
		else res[x]=s[x]-sum;
	}
		for(int v:edges[x])
		{
			if(!vis[v])
			{
				//if(v==3)
				//	System.out.println("F "+(res[x])+" "+sum+" "+x);
				dfs2(v,dep+1,Math.max(0,sum+res[x]));
			}
		}

	}
		public static void main(String[] args)  throws Exception 
	      {
		
			//	scan=new FastScanner("help.in");
			//out = new PrintWriter("lifeguards.out");
			 
			 /*
			 currently doing 
			 1-digit dp
			 2-ds like fenwick and interval tree and sparse table 
			 */
			 /*
			 READING 
			 1-Everything About Dynamic Programming codeforces
			 2-DYNAMIC PROGRAMMING: FROM NOVICE TO ADVANCED topcoder
			 3-Introduction to DP with Bitmasking codefoces
			 4-Bit Manipulation hackerearth
			 5-read more about mobious and inculsion-exclusion 
			 */


			    int tt=1;
			 
	
//System.out.println(Mobius(3));
//tt=scan.nextInt();
//System.out.println(997638343884L>392047955148L);
//System.out.println(Mobius(6));
//least_prime_factor();
 //Mobius();
	 //System.out.println(mobius[2]+" "+Mobius(2));
/*	 for(int i=1;i<=5000;i++)
	 	if(mobius[i]!=Mobius(i))
	 		System.out.println(i);*/
		 outer:while(tt-->0)
			    {
			    	int n=scan.nextInt();
			    	edges=new LinkedList[n];
			    	for(int i=0;i<n;i++)
			    		edges[i]=new LinkedList();
			    	for(int i=1;i<=n-1;i++)
			    	{
			    		int x=scan.nextInt()-1;
			    		edges[i].add(x);
			    		edges[x].add(i);
			    	}
			    	s=new int[n];
			    	for(int i=0;i<n;i++)
			    		s[i]=scan.nextInt();
			    	dfs(0,Integer.MIN_VALUE,1);
			    	Arrays.fill(vis,false);
			    	res=new int[n];
			    	Arrays.fill(res,-1);
			    	dfs1(0,1);
			    	Arrays.fill(vis,false);
			    res[0]=s[0];
			    for(int i=0;i<n;i++)
			    	res[i]=s[i];
			   // for(int i=0;i<n;i++)
			    	//System.out.println("PLEASE "+s[i]);
			    	dfs2(0,1,0);

			    	long sum=0;
			    	for(int i=0;i<n;i++){
			    		//System.out.println("SPOT "+res[i]);
			    		if(res[i]!=-1)
			    	
			    		sum+=res[i];
			    	}
			    	System.out.println(sum);


			    	
	

	}

			  	    out.close();
	 		  
			   
			}
			static class special{
				long x1,y1,x2,y2;
				//int id;
				special(long x1,long y1,long x2,long y2)
				{
					this.x1=x1;
					this.y1=y1;
					this.x2=x2;
					this.y2=y2;
					//this.id=id;
				}
				@Override
				    public int hashCode() {
			                int hash = 7;
    hash = 31 * hash + (int) x1;
    hash = 31 * hash + (int)x2;
    hash = 31 * hash + (int)y1;
    hash = 31 * hash + (int)y2;
    return hash;
			            }
			              @Override
			            public boolean equals(Object o){
			                if (o == this) return true;
			                if (o.getClass() != getClass()) return false;
			                special t = (special)o;
			                return t.x1 == x1 && t.y1 == y1&&t.x2==x2&&t.y2==y2;
			            }
			}

			   
			     static long binexp(long a,long n)
			    {
			        if(n==0)
			            return 1;
			        long res=binexp(a,n/2);
			        if(n%2==1)
			            return res*res*a;
			        else 
			            return res*res;
			    }
			     
			    static long powMod(long base, long exp, long mod) {
			           if (base == 0 || base == 1) return base;
			           if (exp == 0) return 1;
			           if (exp == 1) return (base % mod+mod)%mod;
			           long R = (powMod(base, exp/2, mod) % mod+mod)%mod;
			           R *= R;
			           R %= mod;
			           if ((exp & 1) == 1) {
			               return (base * R % mod+mod)%mod;
			           }
			           else return (R %mod+mod)%mod;
			       }
			    static double dis(double x1,double y1,double x2,double y2)
			    {
			        return Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
			    }
			    static long mod(long x,long y)
			        {
			            if(x<0)
			                x=x+(-x/y+1)*y;
			            return x%y;
			        }
			     public static  long pow(long b, long e) {
			                long r = 1;
			                while (e > 0) {
			                    if (e % 2 == 1) r = r * b ;
			                    b = b * b;
			                    e >>= 1;
			                }
			                return r;
			            }
			    private static void sort(long[] arr) {
			            List<Long> list = new ArrayList<>();
			            for (long object : arr) list.add(object);
			            Collections.sort(list);
			        //Collections.reverse(list);
			            for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i);
			        }
			    private static void sort2(long[] arr) {
			            List<Long> list = new ArrayList<>();
			            for (Long object : arr) list.add(object);
			            Collections.sort(list);
			        Collections.reverse(list);
			            for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i);
			        }
			     static class FastScanner
	{
	    private int BS = 1 << 16;
	    private char NC = (char) 0;
	    private byte[] buf = new byte[BS];
	    private int bId = 0, size = 0;
	    private char c = NC;
	    private double cnt = 1;
	    private BufferedInputStream in;
	 
	    public FastScanner() {
	        in = new BufferedInputStream(System.in, BS);
	    }
	 
	    public FastScanner(String s) {
	        try {
	            in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
	        } catch (Exception e) {
	            in = new BufferedInputStream(System.in, BS);
	        }
	    }
	 
	    private char getChar() {
	        while (bId == size) {
	            try {
	                size = in.read(buf);
	            } catch (Exception e) {
	                return NC;
	            }
	            if (size == -1) return NC;
	            bId = 0;
	        }
	        return (char) buf[bId++];
	    }
	 
	    public int nextInt() {
	        return (int) nextLong();
	    }
	 
	    public int[] nextInts(int N) {
	        int[] res = new int[N];
	        for (int i = 0; i < N; i++) {
	            res[i] = (int) nextLong();
	        }
	        return res;
	    }
	 
	    public long[] nextLongs(int N) {
	        long[] res = new long[N];
	        for (int i = 0; i < N; i++) {
	            res[i] = nextLong();
	        }
	        return res;
	    }
	 
	    public long nextLong() {
	        cnt = 1;
	        boolean neg = false;
	        if (c == NC) c = getChar();
	        for (; (c < '0' || c > '9'); c = getChar()) {
	            if (c == '-') neg = true;
	        }
	        long res = 0;
	        for (; c >= '0' && c <= '9'; c = getChar()) {
	            res = (res << 3) + (res << 1) + c - '0';
	            cnt *= 10;
	        }
	        return neg ? -res : res;
	    }
	 
	    public double nextDouble() {
	        double cur = nextLong();
	        return c != '.' ? cur : cur + nextLong() / cnt;
	    }
	 
	    public double[] nextDoubles(int N) {
	        double[] res = new double[N];
	        for (int i = 0; i < N; i++) {
	            res[i] = nextDouble();
	        }
	        return res;
	    }
	 
	    public String next() {
	        StringBuilder res = new StringBuilder();
	        while (c <= 32) c = getChar();
	        while (c > 32) {
	            res.append(c);
	            c = getChar();
	        }
	        return res.toString();
	    }
	 
	    public String nextLine() {
	        StringBuilder res = new StringBuilder();
	        while (c <= 32) c = getChar();
	        while (c != '\n') {
	            res.append(c);
	            c = getChar();
	        }
	        return res.toString();
	    }
	 
	    public boolean hasNext() {
	        if (c > 32) return true;
	        while (true) {
	            c = getChar();
	            if (c == NC) return false;
	            else if (c > 32) return true;
	        }
	    }
	}

			     static class Pair implements Comparable<Pair>{
			            public long x, y,z;
			            public Pair(long x1, long y1,long z1) {
			                x=x1;
			                y=y1;
			                z=z1;
			            }
			             public Pair(long x1, long y1) {
			                x=x1;
			                y=y1;
			    
			            }
			            
			            @Override
			            public int hashCode() {
			                return (int)(x + 31 * y);
			            }
			            public String toString() {
			                return x + " " + y+" "+z;
			            }
			            @Override
			            public boolean equals(Object o){
			                if (o == this) return true;
			                if (o.getClass() != getClass()) return false;
			                Pair t = (Pair)o;
			                return t.x == x && t.y == y&&t.z==z;
			            }
			    public int compareTo(Pair o)
			    {
			    
			    	return (int)(x-o.x);
			     
			        }
			     
			    }
			    
			    }

			     
