#include <bits/stdc++.h>
using namespace std;
vector<int> v[100010];
int s[100010];
long long ans = 0;
long long dfs(int x) {
  long long ret;
  if (v[x].size() == 0) {
    ret = s[x];
  } else {
    vector<long long> vec;
    long long mini = 0;
    for (int i = 0; i < v[x].size(); ++i) {
      vec.push_back(dfs(v[x][i]));
      if (vec.back() != -1) mini = vec.back();
    }
    if (s[x] != -1) {
      mini = s[x];
      for (int i = 0; i < vec.size(); ++i) {
        if (vec[i] == -1) {
          vec[i] = mini;
        } else if (vec[i] < mini) {
          printf("-1\n");
          exit(0);
        }
      }
    } else {
      for (int i = 0; i < vec.size(); ++i) {
        if (vec[i] == -1) continue;
        mini = min(mini, vec[i]);
      }
      for (int i = 0; i < vec.size(); ++i) {
        if (vec[i] == -1) {
          vec[i] = mini;
        }
      }
    }
    for (int i = 0; i < vec.size(); ++i) {
      ans += vec[i] - mini;
    }
    ret = mini;
  }
  return ret;
}
int main() {
  int n;
  cin >> n;
  for (int i = 2; i <= n; ++i) {
    int x;
    cin >> x;
    v[x].push_back(i);
  }
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    s[i] = x;
  }
  cout << dfs(1) + ans << endl;
}
