#include <bits/stdc++.h>
using namespace std;
const long long MaxN = 100051;
const long long inf = 1e18;
template <class t>
inline void rd(t &s) {
  s = 0;
  register char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();
  return;
}
long long n;
long long fa[MaxN], val[MaxN];
signed main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  register long long x, ans = 0;
  cin >> n;
  for (long long i = 2; i <= n; ++i) cin >> fa[i];
  for (long long i = 1; i <= n; ++i) {
    cin >> val[i];
    if (val[i] == -1) val[i] = inf;
  }
  for (long long i = 2; i <= n; ++i) val[fa[i]] = min(val[i], val[fa[i]]);
  for (long long i = 1; i <= n; ++i) {
    if (val[i] < val[fa[i]]) {
      cout << "-1" << endl;
      return 0;
    }
    if (val[i] != inf) ans += val[i] - val[fa[i]];
  }
  cout << ans << endl;
  return 0;
}
