#include <bits/stdc++.h>
using namespace std;
long long in[100007], res = 0, flag = 1;
vector<long long> adj[100007];
void dfs(long long s, long long pre_sum) {
  if (flag == 0) return;
  long long val = (in[s] == -1) ? pre_sum : in[s];
  if (pre_sum > val) {
    flag = 0;
    return;
  }
  if (in[s] == -1) {
    long long mn = 1e9;
    for (long long i = 0; i < adj[s].size(); i++) {
      long long val1 = adj[s][i];
      val1 = in[val1];
      val1 = (val1 == -1) ? 0 : val1;
      mn = min(mn, val1);
    }
    if (mn == 1e9) mn = 0;
    val = max(val, mn);
  }
  long long cal = val - pre_sum;
  res += cal;
  for (long long i = 0; i < adj[s].size(); i++) {
    dfs(adj[s][i], val);
  }
}
int main() {
  long long n, a, i;
  cin >> n;
  for (i = 0; i < n - 1; i++) {
    cin >> a;
    adj[a].push_back(i + 2);
  }
  for (i = 0; i < n; i++) cin >> in[i + 1];
  dfs(1, 0);
  res = (flag == 0) ? -1 : res;
  cout << res << "\n";
  return 0;
}
