#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 50;
int n, m, u, v, k, cnt, cnt2;
vector<pair<int, int> > g[N];
bool visited[N];
int mx = INT_MIN;
const int fx[9] = {0, 0, 1, -1, 0, 1, 1, -1, -1};
const int fy[9] = {1, -1, 0, 0, 0, 1, -1, 1, -1};
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
int p[N];
long long second[N];
int main() {
  cin >> n;
  for (int i = 2; i <= n; i++) {
    cin >> p[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> second[i];
  }
  for (int i = 1; i <= n; i++) {
    if (second[i] == -1) {
      second[i] = 1e9 + 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (second[i] < 1e9 + 1) {
      second[p[i]] = min(second[i], second[p[i]]);
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (second[i] < second[p[i]]) {
      cout << -1;
      return 0;
    }
    if (second[i] == 1e9 + 1) {
      continue;
    }
    ans += second[i] - second[p[i]];
  }
  cout << ans;
}
