#include <bits/stdc++.h>
using namespace std;
vector<vector<long long int>> child(100005);
vector<long long int> arr(100005);
void magic();
bool chalo_chale(int prev, int curr, long long int* sum) {
  bool isPossible = true;
  if (arr[curr] > -1 && arr[curr] < prev) {
    return false;
  } else if (arr[curr] > -1) {
    (*sum) += (arr[curr] - prev);
    prev = arr[curr];
  }
  for (int i = 0; i < child[curr].size(); i++) {
    isPossible = isPossible && chalo_chale(prev, child[curr][i], sum);
  }
  return isPossible;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  magic();
  return 0;
}
void magic() {
  long long int n, p;
  cin >> n;
  for (long long int i = 2; i <= n; i++) {
    cin >> p;
    child[p].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  for (int i = n; i > 0; i--) {
    long long int mn = INT_MAX;
    if (child[i].size() > 0 && arr[i] == -1) {
      for (int j = 0; j < child[i].size(); j++) {
        if (arr[child[i][j]] != -1) mn = min(mn, arr[child[i][j]]);
      }
      if (mn != INT_MAX) arr[i] = mn;
    }
  }
  long long int sum = 0;
  bool isPossible = chalo_chale(0, 1, &sum);
  if (!isPossible) sum = -1;
  cout << sum << "\n";
}
