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.util.Arrays;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.util.ArrayList;
import java.io.InputStream;

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

    static class DSumInTheTree {
        long[] val;
        long[] sum;
        ArrayList<Integer>[] arrayList;

        void DFS1(int s, int p) {

            for (int tt : arrayList[s]) {
                if (tt != p) {
                    DFS1(tt, s);
                }
            }
            if (sum[s] == -1) {
                long min = Long.MAX_VALUE;
                for (int tt : arrayList[s]) {
                    if (tt != p) min = Math.min(sum[tt], min);
                }

                if (min == Long.MAX_VALUE) {
                    if (p != -1) min = sum[p];
                }
                sum[s] = min;
            }
        }

        void DFS(int s, int p) {
            if (p != -1) val[s] = sum[s] - sum[p];
            for (int t : arrayList[s]) {
                if (t != p) {
                    DFS(t, s);
                }
            }
        }

        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int n = in.scanInt();
            arrayList = new ArrayList[n + 1];
            val = new long[n + 1];
            sum = new long[n + 1];


            Arrays.fill(val, -1);
            for (int i = 0; i <= n; i++) {
                arrayList[i] = new ArrayList<>();
            }


            for (int i = 2; i <= n; i++) {
                int p = in.scanInt();
                arrayList[p].add(i);
                arrayList[i].add(p);
            }

            for (int i = 1; i <= n; i++) {
                sum[i] = in.scanLong();
            }


            DFS1(1, -1);
            val[1] = sum[1];
            DFS(1, -1);


            long su = 0;
            for (int i = 1; i <= n; i++) {
                if (val[i] < 0) {
                    out.println(-1);
                    return;
                } else {
                    su += val[i];
                }
            }

            out.println(su);

        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int INDEX;
        private BufferedInputStream in;
        private int TOTAL;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (INDEX >= TOTAL) {
                INDEX = 0;
                try {
                    TOTAL = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (TOTAL <= 0) return -1;
            }
            return buf[INDEX++];
        }

        public int scanInt() {
            int I = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    I *= 10;
                    I += n - '0';
                    n = scan();
                }
            }
            return neg * I;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

        public long scanLong() {
            long I = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    I *= 10;
                    I += n - '0';
                    n = scan();
                }
            }
            return neg * I;
        }

    }
}

