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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.FileNotFoundException;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Asgar Javadov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();
            GraphLight graph = in.readTreeByParent(n, false);

            int[] s = in.readIntArray(n);
            int[] a = new int[n];
            int[] pr = new int[n];
            pr[0] = -1;


            if (!dfs(0, -1, graph, s, a, pr)) {
                out.println(-1);
            } else {
                out.println(MathUtils.sum(a));
            }

        }

        private boolean dfs(int v, int p, GraphLight graph, int[] s, int[] a, int[] pr) {
            pr[v] = p;

            if (v == 0) {
                a[v] = s[v];
            } else if (s[v] > -1) {
                a[v] = s[v] - s[p];
            } else {
                int[] edges = graph.getEdgesFrom(v);
                if (edges.length > 1) {
                    int m = Integer.MAX_VALUE;
                    for (int child : edges)
                        if (child != p) {
                            m = Math.min(m, s[child]);
                        }
                    a[v] = m - s[p];
                } else {
                    a[v] = 0;
                }
                s[v] = a[v] + s[p];
            }
            if (a[v] < 0) return false;

            boolean result = true;
            for (int child : graph.getEdgesFrom(v))
                if (child != p) {
                    result &= dfs(child, v, graph, s, a, pr);
                    if (!result) return false;
                }
            return result;
        }

    }

    static class InputReader extends BufferedReader {
        StringTokenizer tokenizer;

        public InputReader(InputStream inputStream) {
            super(new InputStreamReader(inputStream), 32768);
        }

        public InputReader(String filename) {
            super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(readLine());
                } catch (IOException e) {
                    throw new RuntimeException();
                }
            }
            return tokenizer.nextToken();
        }

        public Integer nextInt() {
            return Integer.valueOf(next());
        }

        public int[] readIntArray(int size) {
            int[] array = new int[size];
            for (int i = 0; i < size; i++)
                array[i] = nextInt();
            return array;
        }

        public GraphLight readTreeByParent(int V, boolean inputIsZeroIndexed) {
            int E = V - 1;
            int offset = inputIsZeroIndexed ? 0 : 1;
            int[] u = new int[E];
            int[] v = new int[E];


            for (int node = 0; node < E; node++) {
                u[node] = nextInt() - offset;
                v[node] = node + 1;
            }

            return GraphLight.fromEdgesArray(V, E, u, v, false);
        }

    }

    static class MathUtils {
        public static long sum(int... args) {
            long result = 0L;
            for (int i = 0; i < args.length; ++i)
                result += args[i];
            return result;
        }

    }

    static class OutputWriter extends PrintWriter {
        public OutputWriter(OutputStream outputStream) {
            super(outputStream);
        }

        public OutputWriter(Writer writer) {
            super(writer);
        }

        public OutputWriter(String filename) throws FileNotFoundException {
            super(filename);
        }

        public void close() {
            super.close();
        }

    }

    static class GraphLight {
        private final int V;
        private int E;
        int[][] adj;

        public GraphLight(int V) {
            this.V = V;
            this.adj = new int[V][];
        }

        public GraphLight(int V, int E, int[][] adj) {
            this.V = V;
            this.E = E;
            this.adj = adj;
        }

        public static GraphLight fromEdgesArray(int V, int E, int[] u, int[] v, boolean isDirectedGraph) {
            int[] deg = new int[V];
            for (int i = 0; i < u.length; ++i) {
                deg[u[i]]++;
                if (!isDirectedGraph)
                    deg[v[i]]++;
            }

            int[][] adj = new int[V][];
            for (int i = 0; i < V; ++i)
                adj[i] = new int[deg[i]];

            for (int i = 0; i < u.length; ++i) {
                int from = u[i];
                int to = v[i];
                adj[from][--deg[from]] = to;
                if (!isDirectedGraph)
                    adj[to][--deg[to]] = from;
            }

            return new GraphLight(V, E, adj);
        }

        public int[] getEdgesFrom(int node) {
            return adj[node];
        }


        public GraphLight clone() {
            int[][] adj = new int[this.V][];
            for (int i = 0; i < this.V; ++i)
                adj[i] = Arrays.copyOf(this.adj[i], this.adj[i].length);

            return new GraphLight(this.V, this.E, adj);
        }

    }
}

