#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int n, s[100015], p[100015];
long long ans;
int main() {
  cin >> n;
  for (int i = 1; i < n; ++i) cin >> p[i], --p[i];
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
    if (s[i] == -1) s[i] = inf + 1;
  }
  for (int i = 0; i < n; ++i)
    if (s[i] <= inf) s[p[i]] = min(s[p[i]], s[i]);
  for (int i = 1; i < n; ++i)
    if (s[i] < s[p[i]]) return cout << "-1\n", 0;
  ans = s[0];
  for (int i = 1; i < n; ++i)
    if (s[i] <= inf) ans += s[i] - s[p[i]];
  cout << ans << '\n';
}
