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.awt.*;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
import java.util.Random;
import java.util.StringTokenizer;

public class Main {

    String fileName = "";
    int[][] steps = {{0,1}, {1, 0}};
    int INF = Integer.MAX_VALUE / 10 - 123123;
    //////////////////////    SOLUTION   SOLUTION  SOLUTION    //////////////////////////////

    static int checkBit(int mask, int bit) {
        return (mask >> bit) & 1;
    }

    class Edge{
        int to;
        int dist;
        Edge(int to, int dist){
            this.to = to;
            this.dist = dist;
        }
    }

    class Vertex implements Comparable<Vertex>{
        int ind;
        int dist;
        Vertex(int ind, int dist){
            this.ind = ind;
            this.dist = dist;
        }

        @Override
        public int compareTo(Vertex o) {
            return Integer.compare(this.dist, o.dist);
        }
    }
    long MODULO = 998244353;
    ArrayList<Integer>[] graph;
    int[] s;
    boolean[] used;
    long ans = 0;
    boolean flag = true;
    long[] a;
    long[] min;
    void solve() throws IOException {
        int n = readInt();
        graph = new ArrayList[n];
        used = new boolean[n];
        a = new long[n];
        s = new int[n];
        min = new long[n];
        for (int i=0; i<n; ++i) graph[i] = new ArrayList<>();
        for (int i=1; i<n; ++i){
            graph[readInt() - 1].add(i);
        }
        for (int i=0; i<n; ++i) s[i] = readInt();
        minDfs(0);
        Arrays.fill(used, false);
        dfs(0, 0, 0);
        for (int i=0; i<n; ++i){
            if (a[i] < 0) flag = false;
            ans += a[i];
        }
        out.println(flag?ans:-1);
    }
    long minDfs(int from){
        used[from] = true;
        min[from] = Long.MAX_VALUE;
        if (s[from] != -1) min[from] = s[from];
        for (int to: graph[from]){
            if (!used[to]) min[from] = Math.min(min[from], minDfs(to));
        }
        return min[from];
    }
    void dfs(int from, long sum, int p){
        used[from] = true;
        if (s[from] != -1) {
            a[from] = s[from] - sum;
        }else{

            if (min[from] == Long.MAX_VALUE) min[from] = sum;
            a[from] = min[from] - sum;

        }

        for (int to: graph[from])
            if (!used[to]) dfs(to, sum + a[from], from);
    }

    ////////////////////////////////////////////////////////////



    int gcd(int a, int b){
        return b == 0 ? a : gcd(b, a%b);
    }
    long gcd(long a, long b){
        return b == 0 ? a : gcd(b, a%b);
    }
    long binPow(long a, long pow, long MODULO){
        if (pow == 0) return 1;
        if (pow % 2 == 1) {
            return a * binPow(a, pow - 1, MODULO);
        } else {
            long c = binPow(a, pow / 2, MODULO);
            return c * c % MODULO;
        }
    }

    int minInt(int... values) {
        int min = Integer.MAX_VALUE;
        for (int value : values) min = Math.min(min, value);
        return min;
    }

    int maxInt(int... values) {
        int max = Integer.MIN_VALUE;
        for (int value : values) max = Math.max(max, value);
        return max;
    }
    public static void main(String[] args) throws NumberFormatException, IOException {
        // TODO Auto-generated method stub
        new Main().run();
    }

    void run() throws NumberFormatException, IOException {
        solve();
        out.close();
    };

    BufferedReader in;
    PrintWriter out;

    StringTokenizer tok;
    String delim = " ";

    Main() throws FileNotFoundException {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Exception e) {
            if (fileName.isEmpty()) {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
            } else {
                in = new BufferedReader(new FileReader(fileName + ".in"));
                out = new PrintWriter(fileName + ".out");
            }

        }
        tok = new StringTokenizer("");
    }

    String readLine() throws IOException {
        return in.readLine();
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            String nextLine = readLine();
            if (null == nextLine) {
                return null;
            }

            tok = new StringTokenizer(nextLine);
        }
        return tok.nextToken(delim);
    }

    int readInt() throws NumberFormatException, IOException {
        return Integer.parseInt(readString());
    }
    byte readByte() throws NumberFormatException, IOException {
        return Byte.parseByte(readString());
    }
    int[] readIntArray (int n) throws NumberFormatException, IOException {
        int[] a = new int[n];
        for(int i=0; i<n; ++i){
            a[i] = readInt();
        }
        return a;
    }

    Integer[] readIntegerArray (int n) throws NumberFormatException, IOException {
        Integer[] a = new Integer[n];
        for(int i=0; i<n; ++i){
            a[i] = readInt();
        }
        return a;
    }

    long readLong() throws NumberFormatException, IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws NumberFormatException, IOException {
        return Double.parseDouble(readString());
    }
}