#include <bits/stdc++.h>
using namespace std;
int n, fa[210001], son[210001], bro[210001], v[210001], sum[210001],
    Min[210001];
void addt(int a, int b) {
  bro[b] = son[a];
  fa[b] = a;
  son[a] = b;
}
void read() {
  int ls1;
  scanf("%d", &n);
  for (int i = 2; i <= n; ++i) scanf("%d", &ls1), addt(ls1, i);
  for (int i = 1; i <= n; ++i) scanf("%d", sum + i), Min[i] = 1e9 + 1;
  return;
}
void dfs(int a) {
  if (sum[a] != -1) Min[a] = sum[a];
  for (int b = son[a]; b; b = bro[b]) {
    dfs(b);
    if (Min[b] < sum[a]) printf("-1\n"), exit(0);
    Min[a] = min(Min[a], Min[b]);
  }
}
void dfs2(int a) {
  v[a] = Min[a] - Min[fa[a]];
  if (Min[a] == 1e9 + 1) v[a] = 0;
  for (int b = son[a]; b; b = bro[b]) {
    dfs2(b);
  }
}
int main() {
  read();
  dfs(1);
  dfs2(1);
  long long Ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (Min[i] < sum[i]) printf("-1\n"), exit(0);
  }
  for (int i = 1; i <= n; ++i) Ans += v[i];
  cout << Ans << endl;
  return 0;
}
