#include <bits/stdc++.h>
using namespace std;
const int maxn = 112345;
const int inf = 0x3f3f3f3f;
int n, p[maxn], s[maxn], val[maxn];
bool flag;
vector<int> G[maxn];
void dfs(int u) {
  if (s[u] == -1) {
    int mmax = inf;
    for (int i = 0; i < (int)G[u].size(); ++i)
      mmax = min(mmax, s[G[u][i]] - s[p[u]]);
    if (mmax == inf) mmax = 0;
    if (mmax < 0)
      flag = true;
    else
      val[u] = mmax, s[u] = s[p[u]] + val[u];
  } else
    val[u] = s[u] - s[p[u]];
  for (int i = 0; i < (int)G[u].size(); ++i) {
    int v = G[u][i];
    dfs(v);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; ++i) scanf("%d", &p[i]);
  for (int i = 2; i <= n; ++i) G[p[i]].push_back(i);
  for (int i = 1; i <= n; ++i) scanf("%d", &s[i]);
  dfs(1);
  if (flag)
    puts("-1");
  else {
    long long tot = 0;
    for (int i = 1; i <= n; ++i) tot += val[i];
    cout << tot << endl;
  }
  return 0;
}
