#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> g;
vector<long long> s;
vector<long long> p;
vector<long long> a;
bool govno = false;
void dfs(long long v) {
  if (s[v] == -1) {
    long long my_min = 1e9 + 10;
    for (long long it : g[v]) my_min = min(my_min, s[it] - s[p[v]]);
    if (my_min == 1e9 + 10)
      a[v] = 0;
    else
      a[v] = my_min;
    s[v] = a[v] + s[p[v]];
  } else {
    if (v != 0 && s[v] < s[p[p[v]]]) govno = true;
    if (v != 0)
      a[v] = s[v] - s[p[v]];
    else
      a[v] = s[v];
  }
  for (long long it : g[v]) dfs(it);
}
int main() {
  long long n;
  cin >> n;
  g.assign(n, vector<long long>(0));
  p.resize(n);
  a.resize(n);
  s.resize(n);
  for (long long i = 1; i < n; ++i) {
    int x;
    cin >> x;
    x--;
    g[x].push_back(i);
    p[i] = x;
  }
  for (long long i = 0; i < n; ++i) cin >> s[i];
  dfs(0);
  long long ans = 0;
  for (int i = 0; i < n; ++i) ans += a[i];
  if (govno)
    cout << -1 << '\n';
  else
    cout << ans << '\n';
  return 0;
}
