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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;


public class Main {



    public static void main(String[] args) {
        FastScanner fs=new FastScanner();

        long a,b,c,d,sum=0;

        long[] minPossible = new long[100005];
        long[] inp = new long[100005];
        long[] ans = new long[100005];
        int i,j,k,n,m;

        ArrayList<Integer>[] v = new ArrayList[100005];

        n = fs.nextInt();

        for(i=0;i<n;i++){
            v[i] = new ArrayList<>();
        }

        for(i=0;i<n-1;i++){
            m = fs.nextInt();
            v[m-1].add(i+1);
        }

        for(i=0;i<n;i++){
            inp[i] = fs.nextLong();
            minPossible[i]=0;
        }
        if(dfs(inp, minPossible, v,0,0) !=0)
            System.out.println(-1);
        else
        {
            dfsAns(inp, minPossible, v,0,0);
            for(i=0;i<n;i++)
                sum+=minPossible[i];
            System.out.println(sum);
        }


    }

    static long dfs(long[] inp, long[] minPossible, ArrayList<Integer>[] v, int i, long s){

        if(inp[i]==-1){
            minPossible[i]=0;
        }

        else if(inp[i]< s)
            return 1;

        else{
            minPossible[i]=inp[i]-s;
            s+=minPossible[i];
        }

        long temp = 0;
        for(int j=0; j< v[i].size();j++){
            temp+=dfs(inp, minPossible, v,v[i].get(j),s);
        }

        return temp;
    }

    static long dfsAns(long[] inp, long[] minPossible, ArrayList<Integer>[] v, int i, long s){
        long temp = Long.MAX_VALUE;

        for(int j=0; j< v[i].size();j++){
            temp=Math.min(temp, dfsAns(inp, minPossible, v,v[i].get(j),s));
        }

        if(temp > 0 && temp != Long.MAX_VALUE && (inp[i]==-1)){
            for(int j=0; j< v[i].size();j++){
                minPossible[v[i].get(j)]-=temp;
            }
            minPossible[i]+=temp;
        }
        return minPossible[i];
    }

    static void sort(int[] a) {
        ArrayList<Integer> l=new ArrayList<>();
        for (int i:a) l.add(i);
        Collections.sort(l);
        for (int i=0; i<a.length; i++) a[i]=l.get(i);
    }

    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

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

        int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
        long nextLong() {
            return Long.parseLong(next());
        }
    }

}