#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t, n, m, i, j, k;
  cin >> n;
  vector<ll> v[100001];
  ll a[100001] = {0};
  ll c[n + 1], b[n + 1];
  for (i = 2; i <= n; i++) {
    cin >> k;
    b[i] = k;
    v[k].push_back(i);
  }
  for (i = 1; i <= n; i++) cin >> c[i];
  for (i = 1; i <= n; i++) {
    if (c[i] == -1) {
      k = INT_MAX;
      for (j = 0; j < v[i].size(); j++) {
        k = min(k, c[v[i][j]]);
      }
      if (k == INT_MAX) k = c[b[i]];
      a[i] = k;
    } else
      a[i] = c[i];
  }
  ll ans = c[1];
  for (i = 1; i <= n; i++) {
    for (j = 0; j < v[i].size(); j++) {
      ans += a[v[i][j]] - a[i];
      if (a[v[i][j]] - a[i] < 0) {
        ans = -1;
        break;
      }
    }
    if (ans == -1) break;
  }
  cout << ans;
}
