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.*;
import static java.lang.Math.*;

public class Sum_in_the_Tree implements Runnable
{
    boolean multiple = false; // for multiple test cases
    long MOD = 998244353;

    @SuppressWarnings("Duplicates")
    void solve() throws Exception
    {
       int n = sc.nextInt();
       TreeMap<Integer, TreeSet<Integer>>  graph = buildDirGraph(n, 0);
       long[] val = new long[n+1];
       for(int i =1 ; i<=n ; i++)
    	   val[i] = sc.nextLong();
      long as = cal(graph ,1, 1 , 0 , val);
       if(!check)
       System.out.println(-1);
       else
    	   System.out.println(as);
    }

  boolean check = true;
    private long cal(TreeMap<Integer, TreeSet<Integer>> graph ,int cur, int d , long se , long[] val) {
    	long ans = 0  ;
    	if(d%2==0) {
			long min = Long.MAX_VALUE ;
			for(int key : graph.get(cur)) {
				if(val[key] < se) {
					check =false;
					return -1;
				}
				min = Math.min(min,val[key] -se);
			}
			if(min!=Long.MAX_VALUE)
			ans+=min;
			for(int key : graph.get(cur)) {
				ans += cal(graph, key, d+1, se+min, val);
			}
			
		}else {
			if(se>val[cur]) {
				check = false;
			return -1;
			}
			ans += val[cur] - se ; 
			for(int key : graph.get(cur)) {
				ans += cal(graph, key, d+1, val[cur], val);
			}			
		}
		return ans;
	}


	class Node implements Comparable<Node>
    {
        int k, pos, idx;
        Node(int K, int P, int I)
        {
            k = K;
            pos = P;
            idx = I;
        }

        @Override
        public int compareTo(Node o)
        {
            return Integer.compare(k, o.k);
        }
    }


    long powmod(long x, long y){
        if(y==0) return 1L;
        long t=powmod(x,y/2);
        if (y%2==0) return (t*t)%MOD;
        return (((x*t)%MOD)*t)%MOD;
    }
    long inv(long a, long b){return 1<a ? b - inv(b%a,a)*b/a : 1;}
    TreeMap<Integer, TreeSet<Integer>> buildGraph(int n, int m) throws Exception{TreeMap<Integer, TreeSet<Integer>> graph = new TreeMap<>();for (int i = 1; i <= n; i++) graph.put(i, new TreeSet<>());for (int i = 2; i <=n; i++) { int u = i ;int v = sc.nextInt();graph.get(u).add(v);graph.get(v).add(u); }return graph; }
    TreeMap<Integer, TreeSet<Integer>> buildDirGraph(int n, int m) throws Exception { TreeMap<Integer, TreeSet<Integer>> graph = new TreeMap<>();for (int i = 1; i <= n; i++) graph.put(i, new TreeSet<>());for (int i = 2; i <=n; i++) graph.get(sc.nextInt()).add(i);return graph; }
    TreeMap<Integer, TreeSet<Integer>> revGraph(TreeMap<Integer, TreeSet<Integer>> graph) { TreeMap<Integer, TreeSet<Integer>> rev = new TreeMap<>();for (Integer u : graph.keySet()) rev.put(u, new TreeSet<>());for (Integer u : graph.keySet()) for (Integer v : graph.get(u)) rev.get(v).add(u);return rev; }
    TreeMap<Long, Integer> counts(long[] arr) { TreeMap<Long, Integer> counts = new TreeMap<>(); for (long a : arr) { if (!counts.containsKey(a)) counts.put(a, 0); counts.put(a, counts.get(a) + 1);} return counts; }
    String reverse(String s, int i, int j) /*[i, j] closed*/ { return (i > j) ? reverse(s, j, i) : s.substring(0, i) + (new StringBuilder(s.substring(i, j + 1))).reverse() + ((j + 1 <= s.length() - 1) ? s.substring(j + 1) : "");}

    @Override public void run() { try { in = new BufferedReader(new InputStreamReader(System.in));out = new PrintWriter(System.out);sc = new FastScanner(in);if (multiple) { int q = sc.nextInt();for (int i = 0; i < q; i++) solve(); } else solve(); } catch (Throwable uncaught) { Sum_in_the_Tree.uncaught = uncaught; } finally { out.close(); }} public static void main(String[] args) throws Throwable{ Thread thread = new Thread(null, new Sum_in_the_Tree(), "", (1 << 26));thread.start();thread.join();if (Sum_in_the_Tree.uncaught != null) {throw Sum_in_the_Tree.uncaught;} } static Throwable uncaught; BufferedReader in; FastScanner sc; PrintWriter out; } class FastScanner { BufferedReader in; StringTokenizer st; public FastScanner(BufferedReader in) {this.in = in;}public String nextToken() throws Exception { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(in.readLine()); }return st.nextToken(); }public int nextInt() throws Exception { return Integer.parseInt(nextToken()); }public long nextLong() throws Exception { return Long.parseLong(nextToken()); }public double nextDouble() throws Exception { return Double.parseDouble(nextToken()); }
}