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 Main{

    public static void main(String[] args) {

        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader inp = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(inp, out);
        out.close();
        
          }



    static class Solver {


        class Node implements Comparable<Node>{
            int i;
            long c;
          
            Node(int i,long c)
            {
                this.i=i;
                this.c=c;
                

            }

           public int compareTo(Node n)
            {
                return Long.compare(this.c, n.c);
            }
        }

        public boolean done(int[] sp,int[] par)
        {
            int root;

            root=findSet(sp[0],par);
            
           for(int i=1;i<sp.length;i++)
           {
                if(root!=findSet(sp[i], par))
                    return false;
           }
           return true;
        }
       public int findSet(int i,int[] par)
       {
           int x =i;
            boolean flag =false;
            while(par[i]>=0)
            {
                flag = true;
                i=par[i];
            }
            if(flag)
                par[x]=i;
            return i;
       }

       public void unionSet(int i,int j,int[] par)
       {
            int x = findSet(i, par);
            int y = findSet(j, par);
            if(x<y)
            {
                par[y]=x;
            }
            else
            {
                par[x]=y;
            }
       }

       public  long pow(long a, long b, long MOD) {
            if (b == 0) {
                return 1;
            }
            if (b == 1) {
                return a;
            }
            long val = pow(a, b / 2, MOD);
            if (b % 2 == 0) {
                return val * val % MOD;
            } else {
                return val * (val * a % MOD) % MOD;

            }
           
        }


        public void minPrimeFactor(int n,int[] s)
        {
            boolean prime[] = new boolean[n+1];
            Arrays.fill(prime, true);
            s[1]=1;
            s[2]=2;
            for(int i=4;i<=n;i+=2)
            {
                prime[i]=false;
                s[i]=2;
            }

            for(int i=3;i<=n;i+=2)
            {
                if(prime[i])
                {
                    s[i]=i;
                    for(int j=2*i;j<=n;j+=i)
                    {
                        prime[j]=false;
                        s[j]=i;
                    }
                }
            }
            
        }

        
        // public void findAllPrime(int n,ArrayList<Node> al,int s[])
        // {
        //     int curr = s[n];
        //     int cnt = 1;
        //     while(n>1)
        //     {
        //         n/=s[n];
        //         if(curr==s[n])
        //         {
        //             cnt++;
        //             continue;

        //         }
        //         Node n1 = new Node(curr,cnt);
        //         al.add(n1);

        //         curr=s[n];
        //         cnt=1;
        //     }
        // }

        

        public int binarySearch(int n,int k)
        {
            int left=1;
            int right=100000000+5;
            int ans=0;
            while(left<=right)
            {
                int mid = (left+right)/2;
                if(n/mid>=k)
                {
                    left = mid+1;
                    ans=mid;
                }
                else
                {
                    right=mid-1;
                }
            }

            return ans;
        }
        public boolean checkPallindrom(String s)
        {
            char ch[] = s.toCharArray();

            for(int i=0;i<s.length()/2;i++)
            {
                if(ch[i]!=ch[s.length()-1-i])
                    return false;
            }
            return true;
        }


        public void dfs_util(ArrayList<Integer>[] al,boolean vis[],int x,int cnt[],int sts[],int fts[],long sv[])
        {
                
               vis[x] = true;
               long min=Long.MAX_VALUE;
                sts[cnt[0]]=x+1;
                for(int i=0;i<al[x].size();i++)
                {
                    
                    if(!vis[al[x].get(i)])
                    {
                        cnt[0]++;
                        dfs_util(al, vis, al[x].get(i),cnt,sts,fts,sv);
                        if(sv[al[x].get(i)]<min&&sv[al[x].get(i)]!=-1)
                        {
                            min=sv[al[x].get(i)];
                        }
                        
                        
                    }    
                    
                }

             
                if(sv[x]==-1)
                {
                    if(min==Long.MAX_VALUE)
                    {
                        min=-1;
                    }
                    sv[x]=min;
                }
               
            
            return ;
        }

        public void dfs(ArrayList[] al,int sts[],int fts[],long sv[])
        {
            
           boolean vis[] = new boolean[al.length];
           int cnt[]= new int[2*al.length+2];
           for(int i=0;i<al.length;i++)
           {
                if(!vis[i])
                {
                    
                    dfs_util(al,vis,i,cnt,sts,fts,sv);
                }
           }
        }
   
        public void remove(ArrayList<Integer>[] al,int x)
        {
            for(int i=0;i<al.length;i++)
            {
                for(int j=0;j<al[i].size();j++)
                {

                    if(al[i].get(j)==x)
                        al[i].remove(j);

                }
            }
        }

        public int gcd(int a, int b) 
        { 
            if (a == 0) 
                return b; 
            return gcd(b % a, a); 
        }


        public void printDivisors(long n,ArrayList<Long> al) 
        { 
            // Note that this loop runs till square root 
            for (long i=1; i<=Math.sqrt(n); i++) 
            { 
                if (n%i==0) 
                { 
                    // If divisors are equal, print only one 
                    if (n/i == i) 
                        al.add(i);
           
                    else // Otherwise print both 
                        al.add(i);
                        al.add(n/i);
                } 
            } 
        } 

        private void solve(InputReader inp, PrintWriter out1) {
             
                int n = inp.nextInt();
                ArrayList<Integer> al[] = new ArrayList[n];
                
                for(int i=0;i<n;i++)
                {
                    al[i] = new ArrayList<Integer>();
                }
                
                for(int i=1;i<=n-1;i++)
                {
                    int x = inp.nextInt();
                    x--;
                    al[x].add(i);
                }

                long sv[] = new long[n];

                for(int i=0;i<n;i++)
                {
                    sv[i] = inp.nextLong();

                }

                int sts[] = new int[2*n+2];
                int fts[] = new int[2*n+2];
                
                dfs(al, sts, fts, sv);
                
                // System.out.println(Arrays.toString(sv));


                Stack<Integer> s = new Stack<Integer>();
                boolean vis[] = new boolean[n];
                long av[] =new long[n];
                s.push(0);
                av[0]=sv[0];
                
                while(!s.isEmpty())
                {
                    int x = s.pop();
                    if(vis[x])
                    {
                        continue;
                    }

                    for(int i=0;i<al[x].size();i++)
                    {
                        if(!vis[al[x].get(i)])
                        {
                            if(sv[al[x].get(i)]==-1)
                            {
                                av[al[x].get(i)]=0;
                            }
                            else
                            {
                                av[al[x].get(i)]=sv[al[x].get(i)]-sv[x];
                            }
                            
                            s.push(al[x].get(i));
                        }
                    }
                }

                // System.out.println(Arrays.toString(av));
                
                long sum=0;
                for(int i=0;i<n;i++)
                {
                    if(av[i]<0)
                    {
                        out1.println(-1);
                        return;
                    }
                    sum+=av[i];

                }

                out1.println(sum);
            }

}





    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }
    }
}
class ele{
    long value;
    long i;
    boolean flag;
    public ele(long value,long i)
    {
        this.value = value;
        this.i=i;
        this.flag = false;
    }
}
