#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> adj[100005];
int val[100005];
int val2[100005];
void dfs(int sc, int p, int sum) {
  if (val[sc] != -1)
    if (val[sc] < sum) {
      cout << -1;
      exit(0);
    }
  if (val[sc] == -1) {
    for (int i = 0; i != adj[sc].size(); i++) {
      int v = adj[sc][i];
      dfs(v, sc, sum);
    }
  } else {
    for (int i = 0; i != adj[sc].size(); i++) {
      int v = adj[sc][i];
      dfs(v, sc, val[sc]);
    }
  }
}
void dfs2(int sc, int sum) {
  if (!adj[sc].size()) {
    if (val[sc] == -1) {
      val2[sc] = 0;
    } else {
      val2[sc] = val[sc] - sum;
    }
    return;
  }
  int mini = 1e9;
  mini++;
  if (val[sc] == -1) {
    for (int i = 0; i != adj[sc].size(); i++) {
      int v = adj[sc][i];
      mini = min(mini, val[v]);
    }
    val2[sc] = (mini - sum);
  } else {
    val2[sc] = val[sc] - sum;
  }
  for (int i = 0; i != adj[sc].size(); i++) {
    int v = adj[sc][i];
    dfs2(v, sum + val2[sc]);
  }
}
int main() {
  int T, x, y, z;
  T = 1;
  for (int tc = 1; tc <= T; tc++) {
    int n;
    cin >> n;
    for (int i = 2; i <= n; i++) {
      cin >> x;
      adj[x].push_back(i);
    }
    for (int i = 1; i <= n; i++) {
      cin >> val[i];
    }
    dfs(1, -1, 0);
    dfs2(1, 0);
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
      ans += (val2[i]);
    }
    cout << ans << endl;
  }
}
