#include <bits/stdc++.h>
using namespace std;
const long long mxN = 1e5 + 5;
vector<long long> adj[mxN];
multiset<long long> min_adj[mxN];
vector<long long> parents(mxN, -1);
bool ok = 1;
vector<long long> ans, sums(mxN);
void dfs(long long S, long long cur_sum, long long prev) {
  if (S == prev) return;
  if (!ok) return;
  if (sums[S] == -1) {
    if (!min_adj[S].empty()) {
      if (*min_adj[S].begin() < sums[parents[S]]) {
        ok = 0;
        return;
      }
      ans.push_back(*min_adj[S].begin() - sums[parents[S]]);
      sums[S] = *min_adj[S].begin();
    }
  } else {
    if (S != 0 && ok) {
      ans.push_back(sums[S] - sums[parents[S]]);
      cur_sum += sums[S] - sums[parents[S]];
    }
  }
  for (auto u : adj[S]) {
    dfs(u, cur_sum, S);
  }
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long N;
  cin >> N;
  for (long long i = 0; i < N - 1; i++) {
    long long A;
    cin >> A;
    A--;
    adj[A].push_back(i + 1);
    parents[i + 1] = A;
  }
  for (long long i = 0; i < N; i++) {
    cin >> sums[i];
  }
  for (long long i = 0; i < N; i++) {
    for (auto j : adj[i]) {
      min_adj[i].insert(sums[j]);
    }
  }
  dfs(0, sums[0], -1);
  long long sum = sums[0];
  for (auto x : ans) sum += x;
  if (!ok)
    cout << -1 << "\n";
  else
    cout << sum << "\n";
}
