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

public class Test10 {

    Random rnd = new Random();
    PrintWriter pw = new PrintWriter(System.out);
    ArrayList<Integer>[] l;
    long[] s;
    long[] o;
    boolean fl = true;
    long summ=0, cnt=0;
    int a;

    void run() {
        a = ni();
        l = new ArrayList[a];
        o = new long[a];
        s = new long[a];
        for(int q=0; q<a; q++) l[q] = new ArrayList<>();
        for(int q=0; q<a-1; q++){
            int x = ni()-1;
            l[q+1].add(x);
            l[x].add(q+1);
        }
        for(int q=0; q<a; q++) s[q] = nl();
       dfs(0, -1, s[0]);
       dfs2(0,-1, 0);
       long so = 0;
       for(long u : o) so+=u;
        pw.print(fl ? so : -1);
        pw.flush();
    }

    void dfs2(int v, int p, long ns){
        if(l[v].size()==1 && l[v].get(0)==p){
            o[v] = s[v]==-1 ? 0 : s[v]-ns;
            return;
        }
        if(s[v]==-1){
            long min = Long.MAX_VALUE;
            for(int h : l[v]){
                if(h==p) continue;
                min = Math.min(min, s[h]);
            }
            o[v] = min-ns;
            ns += o[v];
        }
        else{
            o[v] = s[v]-ns;
            ns = s[v];
        } 
        for(int h : l[v]){
            if(h==p) continue;
            dfs2(h,v, ns);
        }
    }

    long dfs(int v, int p, long maxv){
        if(s[v]<maxv && s[v]!=-1){
            fl = false;
            return -1;
        }
        if(l[v].size()==1 && l[v].get(0)==p) return s[v]==-1 ? maxv : s[v];
        for(int h : l[v]){
            if(h==p) continue;
            dfs(h,v,Math.max(s[v], maxv));
        }
        return 0;
    }

    public static void main(String[] args) {
        new Test10().run();
    }

    InputStream is = System.in;
    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private 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++];
    }

    private boolean isSpaceChar(int c) {
        return !(c >= 33 && c <= 126);
    }

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

    private double nd() {
        return Double.parseDouble(ns());
    }

    private char nc() {
        return (char) skip();
    }

    private String nline(){
        int b = readByte();
        StringBuilder sb = new StringBuilder();
        while (b!=10) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

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

    private char[] ns(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);
    }

    private char[][] nm(int n, int m) {
        char[][] map = new char[n][];
        for (int i = 0; i < n; i++) map[i] = ns(m);
        return map;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = ni();
        return a;
    }

    private int ni() {
        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 * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl() {
        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 * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }
}