#include <bits/stdc++.h>
const int N = 5e5 + 10, M = 1e7 + 10;
const long long mod = 1e9 + 7;
using namespace std;
int s[N], fa[N];
long long ans;
int main() {
  int n;
  cin >> n;
  for (int i = 2; i <= n; i++) scanf("%d", &fa[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &s[i]);
  for (int i = 1; i <= n; i++)
    if (s[i] == -1) s[i] = 0x3f3f3f3f;
  for (int i = 2; i <= n; i++) s[fa[i]] = min(s[i], s[fa[i]]);
  for (int i = 1; i <= n; i++) {
    if (s[i] < s[fa[i]]) return puts("-1"), 0;
    if (s[i] < 0x3f3f3f3f) ans += s[i] - s[fa[i]];
  }
  cout << ans << endl;
  return 0;
}
