#include <bits/stdc++.h>
using namespace std;
int p1[100006];
int p[100005];
long long int a[100005], s[100005];
vector<int> v[100005];
void dfs(int x) {
  if (s[x] == -1) {
    s[x] = 1e18;
    for (auto i : v[x]) {
      s[x] = min(s[x], s[i]);
    }
    if (s[x] == 1e18) {
      s[x] = s[p[x]];
    }
  }
  for (auto i : v[x]) dfs(i);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 2; i <= n; i++) {
    cin >> p[i];
    v[p[i]].push_back(i);
  }
  for (int i = 1; i <= n; i++) cin >> s[i];
  dfs(1);
  long long int res = 0;
  for (int i = 1; i <= n; i++) {
    a[i] = s[i] - s[p[i]];
    if (a[i] < 0) {
      cout << -1 << endl;
      return 0;
    }
    res += a[i];
  }
  cout << res << endl;
  return 0;
}
