#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 10;
int fa[maxn];
long long sum[maxn];
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  long long ans = 0;
  cin >> n;
  for (int i = 2; i <= n; i++) {
    cin >> fa[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> sum[i];
    if (sum[i] == -1) sum[i] = 1e9 + 1;
  }
  for (int i = 2; i <= n; i++) {
    sum[fa[i]] = sum[fa[i]] < sum[i] ? sum[fa[i]] : sum[i];
  }
  for (int i = 2; i <= n; i++) {
    int temp = sum[i] - sum[fa[i]];
    if (temp < 0) return cout << -1 << endl, 0;
    if (sum[i] <= 1e9) ans += temp;
  }
  cout << sum[1] + ans << endl;
}
