import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

immutable long INF = 1L << 59;

void main() {
    auto N = readln.chomp.to!int;
    auto P = readln.split.map!(to!int).array;
    auto S = readln.split.map!(to!long).array;
    auto X = new long[](N);
    auto G = new int[][](N);
    foreach (i; 0..N-1) {
        G[P[i]-1] ~= i+1;
        G[i+1] ~= P[i]-1;
    }

    bool ok = true;
    long ans = 0;

    long dfs(int n, int p) {
        long ret = S[n];
        if (ret == -1) ret = INF;
        foreach (m; G[n]) {
            if (m == p) continue;
            auto v = dfs(m, n);
            if (v < S[n]) ok = false;
            ret = min(ret, v);
        }
        X[n] = ret;
        return ret;
    }

    void dfs2(int n, int p, long s) {
        if (X[n] == INF) return;
        long a = X[n] - s;
        ans += a;
        foreach (m; G[n]) {
            if (m == p) continue;
            dfs2(m, n, X[n]);
        }
    }

    dfs(0, -1);

    if (!ok) {
        writeln(-1);
        return;
    }

    dfs2(0, -1, 0);

    ans.writeln;
}
