#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7, INF = 1e9 + 7;
int par[N];
int mn[N];
int s[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  fill(mn, mn + N, INF);
  par[1] = 0;
  s[0] = 0;
  for (int i = 2; i <= n; i++) {
    cin >> par[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    if (s[i]) mn[par[i]] = min(mn[par[i]], s[i]);
  }
  for (int i = 1; i <= n; i++)
    if (s[i] == -1) {
      s[i] = mn[i];
      if (s[i] == INF) s[i] = s[par[i]];
    }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    int a = s[i] - s[par[i]];
    if (a < 0) {
      cout << -1 << endl;
      return 0;
    }
    ans += a;
  }
  cout << ans << endl;
}
