#include <bits/stdc++.h>
using namespace std;
vector<vector<long long int>> grp;
vector<long long int> sum;
long long int dfs(long long int i, long long int p, long long int val) {
  long long int ans = 0;
  if ((sum[i] != -1) && (sum[i] >= val))
    ans += (sum[i] - val);
  else if (sum[i] != -1) {
    cout << -1 << endl;
    exit(0);
  } else {
    long long int mn = INT_MAX;
    for (long long int u : grp[i]) {
      if (u != p) mn = min(mn, sum[u] - val);
    }
    if ((mn >= 0) && (mn < INT_MAX)) {
      ans += mn;
      val += mn;
    }
  }
  for (long long int u : grp[i]) {
    if (u != p) {
      if (sum[i] != -1)
        ans += dfs(u, i, sum[i]);
      else
        ans += dfs(u, i, val);
    }
  }
  return ans;
}
int32_t main() {
  std::ios_base::sync_with_stdio(false);
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t;
  t = 1;
  while (t--) {
    long long int n;
    cin >> n;
    grp.assign(n + 1, vector<long long int>());
    sum.assign(n + 1, 0);
    for (long long int i = 2; i <= n; i++) {
      long long int u;
      cin >> u;
      grp[u].push_back(i);
      grp[i].push_back(u);
    }
    for (long long int i = 1; i <= n; i++) {
      long long int u;
      cin >> u;
      sum[i] = u;
    }
    cout << dfs(1, 1, 0) << endl;
  }
  return 0;
}
