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
/*
    created by: nitin23329
    on Date: 09/06/21
*/

import java.io.*;
import java.util.*;

public class CodeForces {


    /*****************************************WRITING CODE STARTS HERE******************************************/
    static ArrayList<Integer> [] tree;
    static boolean isPossible;
    static int[] ancestorSum;
    static int [] avValues;

    private static void dfs(int curr,int level,int parent,int currAncestorSum){
        int value = inf_int;
        if(level % 2 == 0){
            int childMin = inf_int;
            for(int child : tree[curr])
                if(child != parent)
                    childMin = min2(childMin,ancestorSum[child]);
                if(childMin == inf_int)childMin = currAncestorSum;
                value = childMin - currAncestorSum;
        }else{
            value = ancestorSum[curr] - currAncestorSum;
        }
        if(value<0)isPossible = false;
        avValues[curr] = value;
        currAncestorSum += value;
        for(int child : tree[curr])
            if(child != parent)
                dfs(child,level+1,curr,currAncestorSum);

    }
    private static void solve(int test) {
       int n = sc.nextInt();
       isPossible = true;
       tree = new ArrayList[n+1];
       ancestorSum = new int[n+1];
       avValues  = new int[n+1];
       for(int i=0;i<=n;i++)
           tree[i] = new ArrayList<>();
       for(int child = 2;child<=n;child++){
           int parent = sc.nextInt();
           tree[parent].add(child);
       }
       for(int i=1;i<=n;i++)
           ancestorSum[i] = sc.nextInt();
       dfs(1,1,-1,0);
       if(!isPossible){
           out.println(-1);
           return;
       }

       long totalSum = 0;
       for(int ele : avValues)totalSum += ele;
       out.println(totalSum);
    }


    /*****************************************WRITING CODE ENDS HERE******************************************/

    public static void main(String[] args) {
        FIO();
        int testCase = 1;
//        testCase = sc.nextInt();
        for (int i = 1; i <= testCase; i++) solve(i);
//        out.println(((System.currentTimeMillis()) - start )/1000d);
        closeIO();
    }

    static Scanner sc;                     // FAST INPUT
    static PrintWriter out;                // FAST OUTPUT


    /**************************************HELPER FUNCTION STARTS HERE ************************************/

    public static int mod = (int) 1e9 + 7;
    public static final int inf_int = (int) 2e9;
    public static final long inf_long = (long) 1e14;

    public static final String YES = "YES";
    public static final String NO = "NO";

    public static void sort(int[] a, boolean isAscending) {
        ArrayList<Integer> temp = new ArrayList<>();
        for (int j : a) temp.add(j);
        sort(temp, isAscending);
        for (int i = 0; i < a.length; i++) a[i] = temp.get(i);
    }

    public static void sort(long[] a, boolean isAscending) {
        ArrayList<Long> temp = new ArrayList<>();
        for (long ele : a) temp.add(ele);
        sort(temp, isAscending);
        for (int i = 0; i < a.length; i++) a[i] = temp.get(i);
    }

    public static void sort(List list, boolean isAscending) {
        if (isAscending)
            Collections.sort(list);
        else Collections.sort(list, Collections.reverseOrder());
    }

    // count the length of a number, time O(1)
    public static int countDigitBase10(long n) {
        if (n == 0) return 0;
        return (int) (1 + Math.log10(n));
    }

    // euclidean algorithm
    public static long gcd(long a, long b) {
        // time O(max (loga ,logb))
        long x = Math.min(a, b);
        long y = Math.max(a, b);
        if (y % x == 0) return x;
        return gcd(y % x, x);
    }

    public static long lcm(long a, long b) {
        // lcm(a,b) * gcd(a,b) = a * b
        return (a / gcd(a, b)) * b;
    }

    public static long power(long x, long n) {
        // time O(logn)
        long ans = 1;
        while (n > 0) {
            if ((n & 1) == 1) {
                ans *= x;
                ans %= mod;
                n--;
            } else {
                x *= x;
                x %= mod;
                n >>= 1;
            }
        }
        return ans;
    }

    public static long firstDivisor(long n) {
        if (n == 1 || n == 0) return n;
        for (long i = 2; i * i <= n; i++)
            if (n % i == 0) return i;
        return -1;
    }

    public static long max3(long a, long b, long c) {
        return max2(max2(a, b), c);
    }

    public static long max2(long a, long b) {
        return Math.max(a, b);
    }

    public static long min3(long a, long b, long c) {
        return min2(min2(a, b), c);
    }

    public static long min2(long a, long b) {
        return Math.min(a, b);
    }

    public static int max3(int a, int b, int c) {
        return max2(max2(a, b), c);
    }

    public static int max2(int a, int b) {
        return Math.max(a, b);
    }

    public static int min3(int a, int b, int c) {
        return min2(min2(a, b), c);
    }

    public static int min2(int a, int b) {
        return Math.min(a, b);
    }

    /**************************************HELPER FUNCTION ENDS HERE ************************************/

    /*****************************************FAST INPUT STARTS HERE *************************************/

    public static void FIO() {
        sc = new Scanner();
        out = new PrintWriter(System.out);
    }

    public static void closeIO() {
        out.flush();
        out.close();
    }

    private static class Scanner {
        private final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        private StringTokenizer st = new StringTokenizer("");

        public String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();

        }

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

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public int[] set_int_array(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) arr[i] = nextInt();
            return arr;
        }

        public long[] set_long_array(int n) {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) arr[i] = nextLong();
            return arr;
        }

        public double[] set_double_array(int n) {
            double[] arr = new double[n];
            for (int i = 0; i < n; i++) arr[i] = sc.nextDouble();
            return arr;
        }

        public int[][] set_2D_int_array(int n) {
            return set_2D_int_array(n, n);
        }

        public int[][] set_2D_int_array(int row, int col) {
            int[][] arr = new int[row][col];
            for (int i = 0; i < row; i++)
                for (int j = 0; j < col; j++)
                    arr[i][j] = nextInt();
            return arr;
        }

        public long[][] set_2D_long_array(int n) {
            return set_2D_long_array(n, n);
        }

        public long[][] set_2D_long_array(int row, int col) {
            long[][] arr = new long[row][col];
            for (int i = 0; i < row; i++)
                for (int j = 0; j < col; j++)
                    arr[i][j] = nextLong();
            return arr;
        }

        public char[][] set_2D_char_array(int n) {
            return set_2D_char_array(n, n);
        }

        public char[][] set_2D_char_array(int row, int col) {
            char[][] ch = new char[row][col];
            for (int i = 0; i < row; i++)
                ch[i] = sc.next().toCharArray();
            return ch;
        }
    }
    /*****************************************FAST INPUT ENDS HERE *************************************/
}