#include <bits/stdc++.h>
using namespace std;
const int maxm = 1e5 + 7;
int n;
long long ans;
int f[maxm];
long long s[maxm];
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) scanf("%d", &f[i]);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &s[i]);
    if (s[i] == -1) s[i] = 2147483647;
  }
  for (int i = 2; i <= n; i++) s[f[i]] = min(s[i], s[f[i]]);
  for (int i = 1; i <= n; i++) {
    if (s[i] < s[f[i]]) {
      printf("-1\n");
      return 0;
    }
    if (s[i] < 2147483647) ans += s[i] - s[f[i]];
  }
  printf("%lld\n", ans);
  return 0;
}
