#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
long long ans;
vector<int> g[N];
bool flag;
int n, p, a[N], s[N];
void dfs(int v, int p) {
  if (s[v] == -1) {
    s[v] = (int)(g[v]).size() ? 0x3f3f3f3f : s[p];
    for (auto& u : g[v]) s[v] = min(s[v], s[u]);
  }
  a[v] = s[v] - s[p];
  for (auto& u : g[v]) dfs(u, v);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int i = (2); i < (n + 1); i++) {
    cin >> p;
    g[p].emplace_back(i);
  }
  for (int i = (1); i < (n + 1); i++) cin >> s[i];
  dfs(1, 0);
  for (int i = (1); i < (n + 1); i++) {
    if (a[i] < 0) flag = true;
    ans += a[i];
  }
  cout << (flag ? -1 : ans) << '\n';
}
