#include <bits/stdc++.h>
using namespace std;
int p[100009], A[100009];
vector<int> tree[100009];
long long ans = 0;
void go(int now) {
  if (A[now] != -1) {
    int dif = A[now] - A[p[now]];
    if (dif < 0) {
      puts("-1");
      exit(0);
    }
    ans += dif;
  } else {
    if (tree[now].size() == 0) return;
    int par = A[p[now]], mn = 1e9;
    for (auto& it : tree[now]) mn = min(mn, A[it] - par);
    if (mn < 0) {
      puts("-1");
      exit(0);
    }
    A[now] = par + mn;
    ans += mn;
  }
  for (auto& it : tree[now]) go(it);
}
int main() {
  int N;
  scanf("%d", &N);
  p[1] = 0;
  for (int i = 2; i <= N; i++) {
    scanf("%d", &p[i]);
    tree[p[i]].push_back(i);
  }
  for (int i = 1; i <= N; i++) scanf("%d", &A[i]);
  go(1);
  printf("%lld", ans);
  return 0;
}
