#include <bits/stdc++.h>
using namespace std;
int n, f[100001], s[100001];
long long ans;
int main() {
  cin >> n;
  for (int register i = 2; i <= n; i++) cin >> f[i];
  for (int register i = 1; i <= n; i++) cin >> s[i];
  for (int register i = 1; i <= n; i++)
    if (s[i] == -1) s[i] = 1e9 + 1;
  for (int register i = 2; i <= n; i++) s[f[i]] = min(s[i], s[f[i]]);
  for (int register i = 1; i <= n; i++) {
    if (s[i] < s[f[i]]) {
      cout << "-1" << endl;
      return 0;
    }
    if (s[i] <= 1e9) ans += s[i] - s[f[i]];
  }
  cout << ans << endl;
  return 0;
}
