#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}
long long min(long long a, long long b) {
  if (a < b) {
    return a;
  } else {
    return b;
  }
}
long long rand_int(long long l, long long r) {
  static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
  return uniform_int_distribution<long long>(l, r)(gen);
}
long long power(long long b, long long e) {
  if (e == 0) return 1;
  if (e % 2)
    return ((b * power((b) * (b), (e - 1) / 2)));
  else
    return power((b) * (b), e / 2);
}
long long modpower(long long b, long long e, long long q) {
  long long MOD = q;
  if (e == 0) return 1;
  if (e % 2)
    return ((b % MOD) * modpower((b % MOD) * (b % MOD), (e - 1) / 2, q)) % MOD;
  else
    return modpower((b % MOD) * (b % MOD), e / 2, q) % MOD;
}
void dpv(vector<long long> v) {
  for (long long i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << '\n';
}
void dpv(vector<pair<long long, long long> > v) {
  for (long long i = 0; i < v.size(); i++) {
    cout << v[i].first << " " << v[i].second << '\n';
  }
}
void dpv(set<long long> v) {
  for (auto i : v) {
    cout << i << " ";
  }
  cout << '\n';
}
long long ceil1(long long x, long long y) {
  long long r = x / y;
  if (x % y == 0) {
    return r;
  } else {
    return r + 1;
  }
}
const long long N = 1e5 + 5;
vector<vector<long long> > adj(N);
long long s[N];
long long a[N];
void dfs(long long x, long long p) {
  if (s[x] != -1) {
    a[x] = s[x] - s[p];
    for (auto i : adj[x]) {
      if (i != p) {
        dfs(i, x);
      }
    }
  } else {
    long long mi = 1e18;
    for (auto i : adj[x]) {
      if (i != p) {
        mi = min(mi, s[i] - s[p]);
      }
    }
    if (mi == 1e18) {
      a[x] = 0;
      s[x] = s[p];
    } else {
      a[x] = mi;
      s[x] = s[p] + mi;
    }
    for (auto i : adj[x]) {
      if (i != p) {
        dfs(i, x);
      }
    }
  }
}
void oblivious() {
  long long n;
  cin >> n;
  for (long long i = 2; i <= n; i++) {
    long long x;
    cin >> x;
    adj[x].push_back(i);
    adj[i].push_back(x);
  }
  for (long long i = 1; i <= n; i++) {
    cin >> s[i];
  }
  dfs(1, 0);
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    if (a[i] < 0) {
      cout << -1 << '\n';
      return;
    }
    ans += a[i];
  }
  cout << ans << '\n';
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    oblivious();
  }
  return 0;
}
