#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int n;
long long ans = 0;
bool vis[N];
vector<int> adj[N];
int c[N];
bool f = 0;
void dfs(int i, int y) {
  vis[i] = 1;
  if (c[i] == -1) {
    if (adj[i].size() > 0) {
      long t = 1e9 + 43;
      for (auto x : adj[i]) {
        if (c[x] < t) {
          t = c[x];
        }
      }
      if (t < y) f = 1;
      ans += t - y;
      y = t;
    }
  } else {
    if (c[i] >= y) {
      ans += c[i] - y;
      y = c[i];
    } else {
      f = 1;
    }
  }
  for (auto v : adj[i]) {
    if (!vis[v]) {
      dfs(v, y);
    }
  }
}
int main() {
  cin >> n;
  int u;
  for (int i = 2; i <= n; i++) {
    cin >> u;
    adj[u].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    cin >> c[i];
  }
  dfs(1, 0);
  if (f) {
    cout << -1;
    return 0;
  }
  cout << ans;
}
