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.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.stream.Stream;

/**
 * @author madi.sagimbekov
 */
public class C1099D {

    private static BufferedReader in;
    private static BufferedWriter out;

    private static List<Integer>[] list;
    private static int[] arr;
    private static int[][] dir = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
    private static boolean[] used;
    private static int[] level;
    private static int[] parent;
    private static long[] a;
    private static boolean possible = true;
    private static long sum = 0;

    public static void main(String[] args) throws IOException {
        open();

        int n = readInt();
        int[] k = readInts();
        a = readLongs();

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

        for (int i = 0; i < n - 1; i++) {
            list[k[i]].add(i + 2);
        }

        level = new int[n + 1];
        parent = new int[n + 1];
        used = new boolean[n + 1];
        level[1] = 1;
        Queue<Integer> q = new LinkedList<>();
        q.add(1);
        used[1] = true;

        while (!q.isEmpty()) {
            int node = q.remove();

            for (int next : list[node]) {
                if (!used[next]) {
                    used[next] = true;
                    parent[next] = node;
                    level[next] = level[node] + 1;

                    if (level[node] % 2 == 0) {
                        if (a[next - 1] - a[parent[node] - 1] < 0) {
                            possible = false;
                        } else {
                            if (a[node - 1] == -1) {
                                a[node - 1] = a[next - 1];
                            } else {
                                a[node - 1] = Math.min(a[node - 1], a[next - 1]);
                            }
                        }
                    }

                    q.add(next);
                }
            }
        }

        if (possible) {
            used = new boolean[n + 1];
            dfs(1);
            if (possible) {
                out.write(sum + "\n");
            } else {
                out.write("-1\n");
            }
        } else {
            out.write("-1\n");
        }

        close();
    }

    private static void dfs(int s) {
        used[s] = true;
        if (parent[s] == 0) {
            sum += a[s - 1];
        } else {
            if (a[s - 1] != -1) {
                if (a[s - 1] - a[parent[s] - 1] >= 0) {
                    sum += a[s - 1] - a[parent[s] - 1];
                } else {
                    possible = false;
                }
            }
        }
        for (int next : list[s]) {
            if (!used[next]) {
                dfs(next);
            }
        }
    }

    private static int[] readInts() throws IOException {
        return Stream.of(in.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }

    private static int readInt() throws IOException {
        return Integer.parseInt(in.readLine());
    }

    private static long[] readLongs() throws IOException {
        return Stream.of(in.readLine().split(" ")).mapToLong(Long::parseLong).toArray();
    }

    private static long readLong() throws IOException {
        return Long.parseLong(in.readLine());
    }

    private static double[] readDoubles() throws IOException {
        return Stream.of(in.readLine().split(" ")).mapToDouble(Double::parseDouble).toArray();
    }

    private static double readDouble() throws IOException {
        return Double.parseDouble(in.readLine());
    }

    private static String readString() throws IOException {
        return in.readLine();
    }

    private static List<Integer>[] buildAdjacencyList(int n, int m) throws IOException {
        List<Integer>[] list = new ArrayList[n + 1];
        for (int i = 0; i <= n; i++) {
            list[i] = new ArrayList<>();
        }

        for (int i = 0; i < m; i++) {
            int[] e = readInts();
            list[e[0]].add(e[1]);
            list[e[1]].add(e[0]);
        }

        return list;
    }

    private static void open() {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new BufferedWriter(new OutputStreamWriter((System.out)));
    }

    private static void close() throws IOException {
        out.flush();
        out.close();
        in.close();
    }

}
