#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> v(100005);
bool visit[100005];
long long value[100005];
long long level[100005];
long long parent[100005];
long long f = 0, s = 0;
void dfs(long long n) {
  if (value[n] == (-1)) {
    long long su = 1e18;
    for (long long i = 0; i < v[n].size(); ++i) {
      if (v[n][i] != parent[n]) su = min(su, value[v[n][i]]);
    }
    if (su == 1e18)
      value[n] = value[parent[n]];
    else
      value[n] = su;
  }
  for (long long i = 0; i < v[n].size(); ++i) {
    if (visit[v[n][i]] == false) {
      visit[v[n][i]] = true;
      level[v[n][i]] = level[n] + 1;
      dfs(v[n][i]);
    }
  }
}
void dfs1(long long n) {
  for (long long i = 0; i < v[n].size(); ++i) {
    if (visit[v[n][i]] == false) {
      s += value[v[n][i]] - value[n];
      visit[v[n][i]] = true;
      if (value[n] > value[v[n][i]]) f = 1;
      dfs1(v[n][i]);
    }
  }
}
long long power(long long x, unsigned long long y, unsigned long long m) {
  if (y == 0) return 1;
  long long p = power(x, y / 2, m) % m;
  p = (p * p) % m;
  return (y % 2 == 0) ? p : (x * p) % m;
}
long long modInverse(long long a, long long m) { return power(a, m - 2, m); }
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long t = 1;
  while (t-- > 0) {
    long long n = 0;
    cin >> n;
    long long a = 0;
    for (long long i = 0; i < n - 1; ++i) {
      cin >> a;
      v[a].push_back(i + 2);
      v[i + 2].push_back(a);
      parent[i + 2] = a;
    }
    for (long long i = 0; i < n; ++i) {
      cin >> value[i + 1];
    }
    visit[1] = true;
    level[1] = 1;
    dfs(1);
    for (long long i = 0; i <= n; ++i) {
      visit[i] = false;
    }
    visit[1] = true;
    s = value[1];
    dfs1(1);
    if (f == 1)
      cout << "-1";
    else
      cout << s;
  }
  return 0;
}
