#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int par[n + 1];
  int sum[n + 1];
  for (int i = 2; i <= n; i++) cin >> par[i];
  for (int i = 1; i <= n; i++) {
    cin >> sum[i];
    if (sum[i] == -1) sum[i] = INT_MAX;
  }
  for (int i = 2; i <= n; i++) sum[par[i]] = min(sum[par[i]], sum[i]);
  long long ans = sum[1];
  for (int i = 2; i <= n; i++) {
    if (sum[i] < sum[par[i]]) {
      cout << "-1\n";
      return 0;
    }
    if (sum[i] <= 1000000000) ans += sum[i] - sum[par[i]];
  }
  cout << ans << "\n";
  return 0;
}
