#include <bits/stdc++.h>
using namespace std;
vector<int> ch[100005];
long long s[100005];
int p[100005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 2; i <= n; ++i) {
    scanf("%d", &p[i]);
    ch[p[i]].push_back(i);
  }
  for (int i = 1; i <= n; ++i) scanf("%lld", &s[i]);
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (s[i] == -1) {
      long long v = 1LL << 60;
      for (int x : ch[i]) {
        v = min(v, s[x] - s[p[i]]);
      }
      if (v < 0) {
        printf("-1\n");
        return 0;
      }
      if (ch[i].empty()) v = 0;
      s[i] = v + s[p[i]];
      ans += v;
    } else
      ans += s[i] - s[p[i]];
  }
  printf("%lld\n", ans);
}
