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.*;
 
 
public class gfg  {

    
    public static void main(String[] args) throws IOException{
        //Reader.init(System.in);
        //PrintWriter out = new PrintWriter(System.out);
        Reader.init(System.in);
        int t = 1;//Reader.nextInt();
        while(t-->0){
           solve();
        }
            //out.close();
    }
    
    static ArrayList<Integer>[] graph; 
    //static ArrayList<Integer>[] set;
    static int n=0;
    static int m=0;
    static boolean[] vis;
    //static char[][] arr;
    static long mod =1000000007;
    static int min=-1;
    //static ArrayList<int[]> list ;
    static int[] s;
    static int[] a;
    static boolean invalid=false;
    static int[] dx = {0,0,-1,1};
    static int[] dy = {1,-1,0,0};



    static void solve()throws IOException{
        n = Reader.nextInt();
        graph = new ArrayList[n+1];
        for(int i=1;i<=n;i++)
            graph[i]  = new ArrayList<Integer>();
        vis = new boolean[n+1];
        s = new int[n+1];
        a = new int[n+1];
        for(int i=2;i<=n;i++){
            int x = Reader.nextInt();
            graph[i].add(x);
            graph[x].add(i);
        }
        for(int i=1;i<=n;i++){
            s[i] = Reader.nextInt();
        }
        a[1]=s[1];
        dfs(1,-1);
        if(invalid){
            System.out.println(-1);
            return;
        }
        long ans=0;
        for(int i=1;i<=n;i++){
            ans+=a[i];
        }
        System.out.println(ans);

    }

    static void dfs(int x, int p){ // u[ar = false means upar edge h;
        vis[x]=true;
        int min = (int)1e9;

        if(s[x]==-1){
            for(int i:graph[x]){
                if(i!=p)
                    min = Math.min(min,s[i]-s[p]);
            }
            if(min==(int)1e9){
                s[x] = s[p];
                a[x]=0;
            }
            else{
                s[x] = s[p]+min;
                a[x] = min;
            }
            if(s[x]<s[p])
                invalid=true;
            for(int i:graph[x]){
                if(i!=p){
                    if(s[x] >s[i] )
                        invalid=true;
                    else
                        a[i] = s[i]-s[x];
                }
            }
        }
        for(int i:graph[x]){
            if(i!=p)
                dfs(i,x);
        }
    }
    

    


    
    
    // ggratest common divisor
    static int gcd(int a , int b){
        if(b==0)
            return a;
        else
            return gcd(b,a%b);
    }
 
    // least common multiple
    static int lcm(int a, int b){
        return (a*b)/gcd(a,b);
    }
    
    // a^b
    static long fastpow(long a, long b){
        long res = 1;a=a%mod;
        while(b>0){
            if(b%2==1)
                res = (res*a)%mod;
            a = (a*a)%mod;
            b = b>>1;
        }
        return res;
    }
 
    
}
 
 
class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;
 
    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                     new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }
 
    /** get next word */
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                   reader.readLine() );
        }
        return tokenizer.nextToken();
    }
 
    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }
    
    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
}
class newcomparator implements Comparator<Integer>{
    //@Override
    public int compare(Integer a, Integer  b){
        return a<=b?1:-1;
    }
 }
class node {
    int a;
    long b;// cost to rreach\
    node(int s,long va){
        a=s;
        b=va;
    }
}
class mergesort{
    static void sort(int l, int h, int[] arr){
        if(l<h){
            int mid = (l+h)/2;
            
            sort(l,mid,arr);
            sort(mid+1,h,arr);
            merge(l,mid,h,arr);
        }
    }
    static void merge(int l, int m , int h , int [] arr){
 
        int[] left = new int[m-l+1];
        int[] right = new int[h-m];
        for(int i= 0 ;i< m-l+1;i++){
            left[i] = arr[l+i];
        }
        for(int i=0;i<h-m;i++){
            right[i] = arr[m+1+i];
        }
        //now left and right arrays are assumed to be sorted and we have tp merge them together 
        // int the original aaray.
        int i=l;
        int lindex = 0;
        int rindex =  0;
        
        while(lindex<m-l+1 && rindex<h-m){
            if(left[lindex]<=right[rindex]){
                arr[i]=left[lindex];
                lindex++;
                i++;
            }
            else{
                arr[i]=right[rindex];
                rindex++;
                i++;
            }
        }
        while(lindex<m-l+1){
            arr[i]=left[lindex];
            lindex++;
            i++;
        }
        while(rindex<h-m){
            arr[i]=right[rindex];
            rindex++;
            i++;
        }
    }
    
}



