#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& s, vector<T> const& v) {
  s << '{';
  for (int i = 0; i < int(v.size()); i++) s << (i ? "," : "") << v[i];
  return s << '}';
}
template <typename S, typename T>
ostream& operator<<(ostream& s, pair<S, T> const& p) {
  return s << '(' << p.first << ',' << p.second << ')';
}
constexpr int MAXN = 100005;
int N, S[MAXN], mn[MAXN];
vector<vector<int> > adj;
int dfs1(int n) {
  int& val = mn[n];
  val = S[n];
  for (int m : adj[n]) val = min(val, dfs1(m));
  return val;
}
long long ans;
bool fail;
void dfs2(int n, int cv) {
  int myval;
  if (mn[n] == INT_MAX)
    myval = 0;
  else if (S[n] == INT_MAX)
    myval = mn[n] - cv;
  else
    myval = S[n] - cv;
  if (myval < 0) {
    fail = true;
    return;
  }
  ans += myval;
  for (int m : adj[n]) dfs2(m, cv + myval);
}
int main() {
  scanf("%d", &N);
  adj.resize(N);
  for (int i = 1; i < int(N); i++) {
    int p;
    scanf("%d", &p);
    --p;
    adj[p].push_back(i);
  }
  for (int n = 0; n < int(N); n++) {
    scanf("%d", S + n);
    if (S[n] == -1) S[n] = INT_MAX;
  }
  dfs1(0);
  dfs2(0, 0);
  if (fail) {
    puts("-1");
    return 0;
  }
  printf("%lld\n", ans);
}
