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
/**
 * Created by Baelish on 1/5/2019.
 */

import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class D {
    public static void main(String[] args)throws Exception {
        FastReader in = new FastReader(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = in.nextInt();
        g = genList(n+1);
        type = new int[n+1];
        last = new long[n+1];
        s = new long[n+1];
        ans = new long[n+1];
        minChild = new long[n+1];
        x =  new int[n+1];
        for (int i = 2; i <= n; i++) {
            int p = in.nextInt();
            g[p].add(i);
        }
        for (int i = 1; i <= n; i++) {
            int c = in.nextInt();
            type[i] = min(0, c);
            s[i] = max(0, c);
        }

        solve(1);
        dfs(1, 0);
        debug(minChild);
        debug(ans);

        if(!ok) pw.println(-1);
        else{
            long res = 0;
            for(long i : ans) res += i;
            pw.println(res);
        }

        pw.close();
    }

    static int type[];
    static long s[], last[], ans[], minChild[];
    static int x[], inf = (int)2e9;
    static List<Integer> g[];
    static boolean ok = true;

    static void solve(int u) {
        minChild[u] = inf;
        if(type[u] == 0) {
            minChild[u] = s[u];
            x[u] = 1;
        }

       // debug(u, x[u], minChild[u]);

        for(int v : g[u]) {
            solve(v);
            if(x[v] == 1) {
                x[u] = 1;
                minChild[u] = min(minChild[u], minChild[v]);
            }
        }
        if(minChild[u] == inf) minChild[u] = 0;
    }

    static void dfs(int u, int p) {
        if(!ok) return;
        last[u] = last[p];
        if(type[u] == 0 && last[u] > s[u]) {
            ok = false; return;
        }
        if(type[u] == 0) {
            ans[u] = s[u] - last[u];
            last[u] = s[u];
        }
        else if(minChild[u] > last[u]){
            ans[u] = minChild[u] - last[u];
            last[u] = minChild[u];
        }

        for (int v : g[u]) {
            dfs(v, u);
        }
    }



    static <T>List<T>[] genList(int n){
        List<T> list[] = new List[n];
        for(int i = 0; i < n; i++) list[i] = new ArrayList<T>();
        return list;
    }

    static void debug(Object...obj) {
        System.err.println(Arrays.deepToString(obj));
    }

    static class FastReader {
        InputStream is;
        private byte[] inbuf = new byte[1024];
        private int lenbuf = 0, ptrbuf = 0;

        public FastReader(InputStream is) {
            this.is = is;
        }

        public int readByte() {
            if (lenbuf == -1) throw new InputMismatchException();
            if (ptrbuf >= lenbuf) {
                ptrbuf = 0;
                try {
                    lenbuf = is.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (lenbuf <= 0) return -1;
            }
            return inbuf[ptrbuf++];
        }

        public boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }
        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

        public int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b)) ;
            return b;
        }

        public String next() {
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while (!(isSpaceChar(b))) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }



        public String nextLine() {
            int c = skip();
            StringBuilder sb = new StringBuilder();
            while (!isEndOfLine(c)){
                sb.appendCodePoint(c);
                c = readByte();
            }
            return sb.toString();
        }

        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

        public long nextLong() {
            long num = 0;
            int b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

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

        public char[] next(int n) {
            char[] buf = new char[n];
            int b = skip(), p = 0;
            while (p < n && !(isSpaceChar(b))) {
                buf[p++] = (char) b;
                b = readByte();
            }
            return n == p ? buf : Arrays.copyOf(buf, p);
        }

        public char readChar() {
            return (char) skip();
        }
    }
}