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.sql.SQLOutput;
import java.util.ArrayList;


import static java.lang.Math.max;
import static java.lang.Math.min;

import java.util.Scanner;

public class Main {
    static int[] tree_prev = null;
    static ArrayList<ArrayList <Integer> > tr = null;
    static long [] dist = null;
    static long [] tree_val = null;
    static boolean global_no = false;
    static long cur_sum = 0;
    static long cur_dist = 0;
    static long pos_inf = 10000000000l;
    public static int dfs(int x){
        //System.out.println("in dfs in" + x + "\n");
        //System.out.println("dist x is " + dist[x] + "\n");
        long val = -1;
        if(dist[x] == -1) {
            if (tr.get(x).size() == 0) {
                dist[x] = pos_inf;
            } else {
                for (int i = 0; i < tr.get(x).size(); i++) {
                    dfs(tr.get(x).get(i));
                    if (val == -1)
                        val = dist[tr.get(x).get(i)];
                    else
                        val = min(val, dist[tr.get(x).get(i)]);
                }
                dist[x] = val;
            }
        }
        else{
            if (tr.get(x).size() == 0) {
                return 0;
            } else {
                for (int i = 0; i < tr.get(x).size(); i++) {
                    dfs(tr.get(x).get(i));
                }
            }
        }
        return 0;
    }

    public static void dfsToCalc(int x){
        long was;
        if(dist[x] == pos_inf)
            tree_val[x] = 0;
        else {
            tree_val[x] = dist[x] - cur_dist;
            was = cur_dist;
            cur_dist += tree_val[x];
            for (int i = 0; i < tr.get(x).size(); i++)
                dfsToCalc(tr.get(x).get(i));
            cur_dist = was;
        }
    }

    public static void dfsCheck(int x){
        if(dist[x] != pos_inf) {
            cur_sum += tree_val[x];
            if (tree_val[x] < 0)
                global_no = true;
            if (dist[x] != cur_sum)
                global_no = true;
            for (int i = 0; i < tr.get(x).size(); i++) {
                dfsCheck(tr.get(x).get(i));
            }
            cur_sum -= tree_val[x];
        }
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n;
        n = scan.nextInt();
        tree_prev = new int[n];
        tree_val = new long[n];
        tr = new ArrayList<>();
        for(int i = 0; i < n; i++)
            tr.add(new ArrayList<>());
        tree_prev[0] = -1;
        for(int i = 1; i < n; i++) {
            tree_prev[i] = scan.nextInt();
            tree_prev[i]--;
            tr.get(tree_prev[i]).add(i);
        }
        dist = new long[n];
        for(int i = 0; i < n; i++)
            dist[i] = scan.nextInt();
        dfs(0);
        dfsToCalc(0);
        dfsCheck(0);
        //System.out.println("ANSWER");
        if(global_no == true) {
            //for(int i = 0; i < n; i++)
            //    System.out.print(dist[i] + " ");
            //System.out.println("\n\n");
            //for(int i = 0; i < n; i++)
            //    System.out.print(tree_val[i] + " ");
            System.out.print("-1");
        }
        else{
            long sum = 0;
            //for(int i = 0; i < n; i++)
            //    System.out.print(tree_val[i] + " ");
            for(int i = 0; i < n; i++)
                sum += tree_val[i];
            //System.out.println("\nTotal ans is  ");
            System.out.print(sum);
        }
    }

}
