#include <bits/stdc++.h>
using namespace std;
bool F = true;
long long sum = 0;
void DFS(int v, int par, vector<vector<int>> &g, vector<long long> &s,
         vector<long long> &a) {
  if (s[v] == -1) {
    if (g[v].size() == 0) return;
    long long m = 2e9;
    for (int u : g[v]) m = min(s[u], m);
    a[v] = m - s[par];
    if (a[v] < 0) {
      F = false;
    }
    for (int u : g[v]) a[u] = s[u] - m;
  }
  sum += a[v];
  for (int u : g[v]) DFS(u, v, g, s, a);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<vector<int>> g(n);
  vector<long long> s(n), a(n);
  for (int i = 1; i < n; ++i) {
    int p;
    cin >> p;
    g[p - 1].push_back(i);
  }
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  a[0] = s[0];
  DFS(0, 0, g, s, a);
  if (!F) {
    cout << -1 << '\n';
  } else {
    cout << sum << '\n';
  }
}
