#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e9 + 7;
long long int inf = 1e9 + 7;
long long int maxn = 1e5 + 5;
vector<vector<long long int> > adj(maxn);
vector<long long int> p(maxn);
vector<long long int> s(maxn);
vector<long long int> ans(maxn, 0);
long long int flag = 0;
void dfs(long long int cur, long long int sm, long long int par) {
  if (s[cur] != -1) {
    ans[cur] = s[cur] - sm;
    if (ans[cur] < 0) {
      flag = 1;
      return;
    }
    sm = s[cur];
  } else {
    long long int mn = inf;
    for (auto x : adj[cur]) {
      if (x != par) {
        mn = min(mn, s[x]);
      }
    }
    if (mn < sm) {
      flag = 1;
      return;
    }
    if (mn == inf) {
      mn = sm;
    }
    ans[cur] = mn - sm;
    sm = mn;
  }
  for (auto x : adj[cur]) {
    if (x != par) {
      dfs(x, sm, cur);
    }
  }
}
void solve() {
  long long int n;
  cin >> n;
  long long int i;
  p[0] = -1;
  for (i = 1; i < n; i++) {
    cin >> p[i];
    p[i]--;
  }
  for (i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (i = 1; i < n; i++) {
    adj[p[i]].push_back(i);
  }
  flag = 0;
  dfs(0, 0, -1);
  long long int sm = 0;
  for (i = 0; i < n; i++) {
    sm += ans[i];
  }
  if (flag == 1) {
    cout << "-1" << '\n';
    ;
    return;
  }
  cout << sm << '\n';
  ;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  while (t--) {
    solve();
  }
}
