Mitya has a rooted tree with n vertices indexed from 1 to n, where the root has index 1. Each vertex v initially had an integer number a_v ≥ 0 written on it. For every vertex v Mitya has computed s_v: the sum of all values written on the vertices on the path from vertex v to the root, as well as h_v — the depth of vertex v, which denotes the number of vertices on the path from vertex v to the root. Clearly, s_1=a_1 and h_1=1.

Then Mitya erased all numbers a_v, and by accident he also erased all values s_v for vertices with even depth (vertices with even h_v). Your task is to restore the values a_v for every vertex, or determine that Mitya made a mistake. In case there are multiple ways to restore the values, you're required to find one which minimizes the total sum of values a_v for all vertices in the tree.

Input

The first line contains one integer n — the number of vertices in the tree (2 ≤ n ≤ 10^5). The following line contains integers p_2, p_3, ... p_n, where p_i stands for the parent of vertex with index i in the tree (1 ≤ p_i < i). The last line contains integer values s_1, s_2, ..., s_n (-1 ≤ s_v ≤ 10^9), where erased values are replaced by -1.

Output

Output one integer — the minimum total sum of all values a_v in the original tree, or -1 if such tree does not exist.

Examples

Input


5
1 1 1 1
1 -1 -1 -1 -1


Output


1


Input


5
1 2 3 1
1 -1 2 -1 -1


Output


2


Input


3
1 2
2 -1 1


Output


-1
#include <bits/stdc++.h>
using namespace std;
namespace patch {
template <typename T>
std::string to_string(const T& n) {
  std::ostringstream stm;
  stm << n;
  return stm.str();
}
}  // namespace patch
const long double PI = 3.14159265358979323846;
long long mdf = 4294967296;
const long long INF = 3e18 + 1337;
int A = 105;
struct Matrix {
  vector<vector<long long>> mx =
      vector<vector<long long>>(A, vector<long long>(A, INF));
  Matrix operator*(const Matrix& other) {
    Matrix temp;
    for (int i = 0; i < A; i++)
      for (int j = 0; j < A; j++)
        for (int k = 0; k < A; k++)
          temp.mx[i][j] = min(mx[i][k] + other.mx[k][j], temp.mx[i][j]);
    return temp;
  };
};
Matrix exp_matrix(Matrix a, int k) {
  Matrix temp;
  for (int i = 0; i < A; i++) temp.mx[i][i] = 0;
  while (k) {
    if (k % 2) temp = temp * a;
    a = a * a;
    k /= 2;
  }
  return temp;
}
long long gcd(long long a, long long b) { return a == 0 ? b : gcd(b % a, a); }
bool isAPrime(long long m) {
  for (long long p = 2; p * p <= m; p++) {
    if (m % p == 0) {
      return false;
    }
  }
  return true;
}
long long binpow(long long a, long long n) {
  if (n == 0) return 1;
  if (n % 2 == 1)
    return (binpow(a, n - 1) * a) % mdf;
  else {
    long long b = binpow(a, n / 2) % mdf;
    return (b * b) % mdf;
  }
}
int count_setbits(int N) {
  int cnt = 0;
  while (N > 0) {
    cnt += (N & 1);
    N = N >> 1;
  }
  return cnt;
}
long long phi(long long n) {
  long long result = n;
  for (long long i = 2; i * i <= n; ++i)
    if (n % i == 0) {
      while (n % i == 0) n /= i;
      result -= result / i;
    }
  if (n > 1) result -= result / n;
  return result;
}
bool compare(pair<int, long long> a, pair<int, long long> b) {
  return a.second < b.second;
}
int mergethem(vector<int>& a, int l, int m, int r) {
  int Inv = 0;
  vector<int> buff(r - l + 1);
  int pos1 = l, pos2 = m + 1, posB = 0;
  while (pos1 <= m && pos2 <= r) {
    if (a[pos1] < a[pos2]) {
      buff[posB++] = a[pos1++];
    } else {
      Inv += m - pos1 + 1;
      buff[posB++] = a[pos2++];
    }
  }
  while (pos1 <= m) buff[posB++] = a[pos1++];
  while (pos2 <= r) buff[posB++] = a[pos2++];
  copy(buff.begin(), buff.end(), a.begin() + l);
  return Inv;
}
int mergesort(vector<int>& a, int l, int r) {
  int curInv = 0;
  if (l == r) return curInv;
  int m = (l + r) / 2;
  curInv += mergesort(a, l, m);
  curInv += mergesort(a, m + 1, r);
  curInv += mergethem(a, l, m, r);
  return curInv;
}
bool cmp(pair<long long, long long> a, pair<long long, long long> b) {
  return a.first > b.first;
}
vector<int> g[100005];
int av[100005];
int sv[100005];
bool good = true;
void gogogo(int u, int cur) {
  if (!good) return;
  if (sv[u] == -1) {
    int mn = 2e9;
    for (int v : g[u]) mn = min(mn, sv[v]);
    if (mn == 2e9)
      av[u] = 0;
    else {
      if (mn < cur) good = false;
      av[u] = mn - cur;
      for (int v : g[u]) gogogo(v, mn);
    }
  } else {
    if (cur > sv[u]) good = false;
    av[u] = sv[u] - cur;
    for (int v : g[u]) gogogo(v, sv[u]);
  }
}
void solve() {
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int j;
    cin >> j;
    j--;
    g[j].push_back(i);
  }
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    sv[i] = x;
  }
  av[0] = sv[0];
  for (int v : g[0]) {
    gogogo(v, av[0]);
  }
  if (good) {
    long long s = 0;
    for (int i = 0; i < n; i++) s += av[i];
    cout << s;
  } else
    cout << -1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int q = 1;
  while (q--) solve();
  return 0;
}
