#include <bits/stdc++.h>
using namespace std;
template <typename T>
T trace2(T a, T b) {
  cerr << a << " " << b << '\n';
}
template <typename T>
T trace3(T a, T b, T c) {
  cerr << a << " " << b << " " << c << '\n';
}
template <typename T>
T trace4(T a, T b, T c, T d) {
  cerr << a << " " << b << " " << c << " " << d << '\n';
}
template <typename T>
T trace5(T a, T b, T c, T d, T e) {
  cerr << a << " " << b << " " << c << " " << d << " " << e << '\n';
}
template <typename T>
T trace6(T a, T b, T c, T d, T e, T f) {
  cerr << a << " " << b << " " << c << " " << d << " " << e << " " << f << '\n';
}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << '\n';
  err(++it, args...);
}
template <typename T>
T pow(T a, T b, long long int m) {
  T ans = 1;
  while (b > 0) {
    if (b % 2 == 1) ans = (ans * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return ans % m;
}
void swap(long long int *a, long long int *b) {
  long long int temp = *a;
  *a = *b;
  *b = temp;
  return;
}
const long long int N = 1e5 + 10;
long long int n;
std::vector<long long int> v[N];
std::vector<long long int> p(N);
std::vector<long long int> s(N);
std::vector<long long int> ans(N, 0);
void wr() {
  cout << -1;
  exit(0);
}
void f(long long int x) {
  long long int l = 10000000000;
  for (auto i : v[x]) {
    l = min(l, s[i]);
  }
  if (l != 10000000000) s[x] = l;
}
void dfs(long long int vertex) {
  if (s[vertex] == -1) {
    f(vertex);
  }
  for (auto i : v[vertex]) {
    dfs(i);
  }
}
void f2(long long int vertex) {
  for (auto i : v[vertex]) {
    if (s[i] == -1) {
      ans[i] = 0;
    } else
      ans[i] = s[i] - s[vertex];
    f2(i);
  }
}
void fuck() {
  cin >> n;
  p[1] = 1;
  for (__typeof(n + 1) i = (2) - ((2) > (n + 1));
       i != (n + 1) - ((2) > (n + 1)); i += 1 - 2 * ((2) > (n + 1))) {
    long long int temp;
    cin >> temp;
    v[temp].push_back(i);
    p[i] = temp;
  }
  for (__typeof(n + 1) i = (1) - ((1) > (n + 1));
       i != (n + 1) - ((1) > (n + 1)); i += 1 - 2 * ((1) > (n + 1)))
    cin >> s[i];
  ans[1] = s[1];
  dfs(1);
  f2(1);
  long long int out = 0;
  for (__typeof(n + 1) i = (1) - ((1) > (n + 1));
       i != (n + 1) - ((1) > (n + 1)); i += 1 - 2 * ((1) > (n + 1))) {
    out += ans[i];
    if (ans[i] < 0) {
      wr();
    }
  }
  cout << out << '\n';
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  fuck();
  return 0;
}
