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.*;
import java.util.*;

public class Solution {
    public static void clean(int x, int y, int orientation) {
        // if in hashSet return
        // add in hashSet
        // if (moveForward)
        // if (orientation == "NORTH") clean(x, y + 1, NORTH)
        // if (orientation == "SOUTH") clean(x, y - 1, SOUTH)
        // if (orientation == "SOUTH") clean(x, y - 1, SOUTH)
        // if (orientation == "SOUTH") clean(x, y - 1, SOUTH)

        // for (int i = orientation + 1; i < orientation + 4; i++) { rotate, clean(x, y, i % 4)}
    }
    static int n;
    static int [] p;
    static int [] s;
    static ArrayList<Integer> adjList[];

//    public static void constructTree(Node node, int index) {
//        for (int i = 0; i < n; i++) {
//            if (p[i] == index) {
//                Node newNode = new Node(s[i]);
//                node.children.add(newNode);
//                constructTree(newNode, i + 1);
//            }
//        }
//    }
//
//    public static void changeValues(Node node, int prev) {
//        for (Node child : node.children) {
//            if (child.val == -1) {
//                child.val = 0;
//                changeValues(child, prev);
//            }
//            else {
//                child.val = child.val - prev;
//                changeValues(child, child.val);
//            }
//        }
//    }
//
//    static boolean problem = false;
//    public static int dfs (Node node) {
//        int res = 0;
//        for (Node child : node.children) {
//            if (child.val <= -1) problem = true;
//            res += dfs(child) + child.val;
//        }
//        return res;
//    }
    static boolean prob;

    // u is parent, v is node itself
    public static void dfs(int u, int v, int sum) {
        for (Integer node : adjList[v]) {
            if (node == u) continue;
            if (s[node] == -1) {
                int min = Integer.MAX_VALUE;
                for (Integer child : adjList[node]) {
                    if (child != v)
                        min = Math.min(s[child], min);
                }
                if (min < sum) {
                    prob = true;
                }
                else {
                    if (min != Integer.MAX_VALUE)
                        s[node] = min;
                    else s[node] = s[v];
                }
            }
            dfs(v, node, s[node]);
        }
    }

    public static long dfsRes(int u, int v) {
        long res = 0;
        for (Integer node : adjList[v]) {
            if (node == u) continue;

            res += (s[node] - s[v]) + dfsRes(v, node);

        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        p = new int[n];
        s = new int[n];
        p[0] = -1;
        adjList = new ArrayList[n];
        for (int i = 0; i < n; i++) {
            adjList[i] = new ArrayList<>();
        }


        for (int i = 1; i < n ; i++) {
            p[i] = sc.nextInt() - 1;
            adjList[i].add(p[i]);
            adjList[p[i]].add(i);
        }

        for (int i = 0; i < n; i++) {
            s[i] = sc.nextInt();
        }

        dfs(-1, 0, s[0]);

        if (prob) {
            System.out.println(-1);
        }
        else {
            System.out.println(s[0] + dfsRes(-1,0));
        }


//        Node root = new Node(s[0]);
//        constructTree(root, 1);
//        changeValues(root, s[0]);
//        int res = dfs(root);
//        if (problem) System.out.println(-1);
//        else System.out.println(res + s[0]);

    }

//    static class Node {
//        ArrayList<Node> children;
//        int val;
//        public Node (int val) {
//            children = new ArrayList<>();
//            this.val = val;
//        }
//    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream System) throws FileNotFoundException {
            br = new BufferedReader(new InputStreamReader(System));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

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

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

        public char nextChar() throws IOException {
            return next().charAt(0);
        }

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

        public boolean ready() throws IOException {
            return br.ready();
        }

        public void waitForInput() {
            for (long i = 0; i < 3e9; i++)
                ;
        }
    }

    static class Edge implements Comparable<Edge> {
        int to;
        int index;
        int w;

        public Edge(int to, int index, int w) {
            this.to = to;
            this.index = index + 1;
            this.w = w;
        }

        @Override
        public int compareTo(Edge o) {
            return this.w - o.w;
        }
    }
}