#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 5;
long long p[maxn], s[maxn];
signed main() {
  long long n;
  cin >> n;
  for (long long i = 2; i <= n; i++) cin >> p[i];
  for (long long i = 1; i <= n; i++) cin >> s[i];
  for (long long i = 2; i <= n; i++) {
    if (~s[i]) {
      s[p[i]] = min(s[i], s[p[i]]);
    } else
      s[i] = 1e9 + 1;
  }
  long long ans = 0;
  for (long long i = 1; i <= n; i++)
    if (s[i] < s[p[i]])
      return puts("-1"), 0;
    else {
      if (s[i] <= 1e9) {
        ans += s[i] - s[p[i]];
      }
    }
  cout << ans;
}
