#include <bits/stdc++.h>
using namespace std;
namespace RikukiIX {
const int N = 100069;
int fa[N];
long long s[N];
long long ans = 0;
int n;
int xi;
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) scanf("%d", &fa[i]);
  for (int i = 1; i <= n; i++)
    scanf("%I64d", &s[i]), s[i] = (s[i] == -1 ? 1145149961 : s[i]);
  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[fa[i]] > s[i]) {
      puts("-1");
      return 0;
    }
    if (s[i] == 1145149961) s[i] = s[fa[i]];
    ans += s[i] - s[fa[i]];
  }
  printf("%I64d\n", ans);
  return 0;
}
}  // namespace RikukiIX
int main() { return RikukiIX::main(); }
