#include <bits/stdc++.h>
using namespace std;
long long s[200010], a[200010];
vector<long long> adj[200010];
bool poss = true;
void dfs(long long loc, long long par) {
  if (s[loc] == -1) {
    for (auto i : adj[loc])
      if (i != par) {
        s[loc] = (s[loc] == -1) ? s[i] : min(s[i], s[loc]);
      }
    if (s[loc] == -1) s[loc] = s[par];
  }
  a[loc] = s[loc] - s[par];
  for (auto i : adj[loc])
    if (i != par) dfs(i, loc);
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m, x;
  cin >> n;
  for (long long i = 2; i <= n; i++) {
    cin >> x;
    adj[x].push_back(i);
  }
  for (long long i = 1; i <= n; i++) {
    cin >> s[i];
  }
  dfs(1, 0);
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    if (a[i] < 0) {
      ans = -1;
      break;
    }
    ans += a[i];
  }
  cout << ans;
  return 0;
}
