#include <bits/stdc++.h>
using namespace std;
int n;
int p[200005];
int s[200005];
int a[200005];
vector<int> child[200005];
void dfs(int u) {
  vector<int>::iterator it;
  int t = 1e9 + 5;
  if (s[u] == -1) {
    if (child[u].empty() == 1) {
      a[u] = 0;
    } else {
      for (it = child[u].begin(); it != child[u].end(); it++)
        t = min(t, s[*it]);
      a[u] = t - s[p[u]];
      s[u] = a[u] + s[p[u]];
    }
  } else {
    if (u == 1)
      a[1] = s[1];
    else
      a[u] = s[u] - s[p[u]];
  }
  if (child[u].empty() == 0) {
    for (it = child[u].begin(); it != child[u].end(); it++) {
      dfs(*it);
    }
  }
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 2; i <= n; i++) {
    cin >> p[i];
    child[p[i]].push_back(i);
  }
  for (int i = 1; i <= n; i++) cin >> s[i];
  dfs(1);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] < 0) {
      cout << -1;
      return 0;
    } else {
      ans += a[i];
    }
  }
  cout << ans;
  return 0;
}
