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.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class Main {
    
    static long res;
    
    public static void main(String[] args) throws UnsupportedEncodingException, IOException, Exception {
        Reader.init(System.in);
        StringBuilder out = new StringBuilder();
        int n = Reader.nextInt();
        Graph g = new Graph(n);
        for(int i = 2; i <= n; i++)
            g.addEdge(Reader.nextInt(), i);
        for(int i = 1; i <= n; i++)
            g.v[i].s = Reader.nextLong();
        if(mistake(g.v[1], null, 0)) {
            System.out.println("-1");
            return;
        }
        dfs(g.v[1], null, false);
        
//        for(int i = 1; i <= n; i++)
//            System.out.println(">>> " + g.v[i].s);
        
        calc(g.v[1], null, 0);
        out.append(res).append('\n');
        PrintWriter pw = new PrintWriter(System.out);
        pw.print(out);
        pw.close();
    }
    
    static void calc(Vertex v, Vertex p, long sum) {
        if(v.s != -1)
            res += v.s - sum;
        for(Vertex c : v.edges)
            if(c != p)
                calc(c, v, v.s == -1 ? sum : v.s);
    }
    
    static long dfs(Vertex v, Vertex p, boolean f) {
        if(v.s != -1) {
            for(Vertex c : v.edges)
                if(c != p)
                    dfs(c, v, false);
            return v.s;
        }
        long s = Long.MAX_VALUE;
        for(Vertex c : v.edges)
            if(c != p)
                s = Math.min(s, dfs(c, v, true));
        if(!f && s != Long.MAX_VALUE) {
            v.s = s;
            s = 0;
        }
        return s == Long.MAX_VALUE ? 0 : s;
    }
    
    static boolean mistake(Vertex v, Vertex p, long sum) {
        if(v.s != -1 && v.s < sum)
            return true;
        for(Vertex c : v.edges)
            if(c != p && mistake(c, v, v.s == -1 ? sum : v.s))
                return true;
        return false;
    }

}

class Vertex {
    
    int name;
    LinkedList<Vertex> edges;
    long s;
    
    public Vertex(int n) {
        name = n;
        edges = new LinkedList<Vertex>();
    }
    
}

class Graph {
    
    Vertex[] v;
    
    public Graph(int s) {
        v = new Vertex[s + 1];
        for(int i = 1; i <= s; i++)
            v[i] = new Vertex(i);
    }
    
    public void addEdge(int v1, int v2) {
        v[v1].edges.add(v[v2]);
        v[v2].edges.add(v[v1]);
    }
    
}

class Reader {

    static BufferedReader reader;
    static StringTokenizer tokenizer;

    static void init(InputStream input) throws UnsupportedEncodingException {
        reader = new BufferedReader(
                new InputStreamReader(input, "UTF-8"));
        tokenizer = new StringTokenizer("");
    }

    static void init(String url) throws FileNotFoundException {
        reader = new BufferedReader(new FileReader(url));
        tokenizer = new StringTokenizer("");
    }

    static String next() throws IOException {
        while (!tokenizer.hasMoreTokens()) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                    reader.readLine());
        }
        return tokenizer.nextToken();
    }

    static String nextLine() throws IOException {
        return reader.readLine();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }
}
