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;
long long modex(long long a, long long b, long long m) {
  if (b == 0) return 1;
  long long ans = a;
  long long save = 1;
  while (b != 1) {
    if (b % 2 == 1) {
      save *= ans;
      save %= m;
    }
    ans *= ans;
    ans %= m;
    b /= 2;
  }
  return (ans * save) % m;
}
long long mx, my;
void solve(long long a, long long b) {
  if (b == 0) {
    mx = 1;
    my = 0;
    return;
  }
  solve(b, a % b);
  long long x1 = mx;
  long long y1 = my;
  mx = y1;
  my = x1 - (a / b) * y1;
}
long long mi(long long x, long long m) {
  solve(x, m);
  return (mx + m) % m;
}
vector<long long> p;
vector<bool> prime;
void seive(int n) {
  prime.resize(n + 1);
  for (int i = 2; i < prime.size(); i++) prime[i] = 1;
  for (int i = 2; i * i <= n; i++) {
    if (!prime[i]) continue;
    int j = i + i;
    while (j <= n) {
      prime[j] = 0;
      j += i;
    }
  }
  for (int i = 2; i <= n; i++)
    if (prime[i]) p.push_back(i);
}
vector<long long> lpd;
void lpdgen(int n) {
  prime.resize(n + 1);
  lpd.resize(n + 1, 0);
  for (int i = 2; i <= n; i++) prime[i] = 1;
  for (int i = 2; i * i <= n; i++) {
    if (!prime[i]) continue;
    int j = i + i;
    while (j <= n) {
      prime[j] = 0;
      if (lpd[j] == 0) lpd[j] = i;
      j += i;
    }
  }
  for (int i = 2; i <= n; i++)
    if (prime[i]) lpd[i] = i;
}
template <typename T>
vector<T> compfactor(T x) {
  vector<T> ret;
  while (x != 1) {
    ret.push_back(lpd[x]);
    x /= lpd[x];
  }
  return ret;
}
template <typename T>
vector<T> pfactor(T x) {
  vector<T> ret;
  while (x != 1) {
    if (ret.size() == 0 || ret[ret.size() - 1] != lpd[x]) ret.push_back(lpd[x]);
    x /= lpd[x];
  }
  return ret;
}
vector<long long> fact;
void factgen(long long n, long long m) {
  fact.resize(n + 1);
  fact[0] = 1;
  for (long long i = 1; i <= n; i++) {
    fact[i] = i * fact[i - 1];
    fact[i] %= m;
  }
}
template <typename T>
vector<T> factor(T x) {
  vector<T> ret;
  for (long long i = 1; i * i <= x; i++) {
    if (i * i == x) {
      ret.push_back(i);
      break;
    }
    if (x % i == 0) {
      ret.push_back(i);
      ret.push_back(x / i);
    }
  }
  return ret;
}
template <typename T>
void init(vector<T>& x, T n) {
  for (int i = 0; i < x.size(); i++) x[i] = n;
}
template <typename T>
void init2(vector<vector<T> >& x, T n) {
  for (int i = 0; i < x.size(); i++)
    for (int j = 0; j < x[i].size(); j++) x[i][j] = n;
}
template <typename T>
void init3(vector<vector<vector<T> > >& x, T n) {
  for (int i = 0; i < x.size(); i++)
    for (int j = 0; j < x[i].size(); j++)
      for (int k = 0; k < x[i][j].size(); k++) x[i][j][k] = n;
}
template <typename T>
void inits2(vector<vector<T> >& x, int a, int b) {
  x.resize(a);
  for (int i = 0; i < x.size(); i++) x[i].resize(b);
}
template <typename T>
void inits3(vector<vector<T> >& x, int a, int b, int c) {
  x.resize(a);
  for (int i = 0; i < x.size(); i++) {
    x[i].resize(b);
    for (int j = 0; j < x[i].size(); j++) x[i][j].resize(c);
  }
}
template <typename T>
T minarr(T* arr, int n) {
  T x = arr[0];
  for (int i = 0; i < n; i++) x = min(x, arr[i]);
  return x;
}
template <typename T>
T maxarr(T* arr, int n) {
  T x = arr[0];
  for (int i = 0; i < n; i++) x = max(x, arr[i]);
  return x;
}
template <typename T>
T minarr(vector<T>& arr) {
  T x = arr[0];
  for (int i = 0; i < arr.size(); i++) x = min(x, arr[i]);
  return x;
}
template <typename T>
T maxarr(vector<T>& arr) {
  T x = arr[0];
  for (int i = 0; i < arr.size(); i++) x = max(x, arr[i]);
  return x;
}
template <typename T>
void prt(vector<T>& x, int n) {
  for (int i = 0; i < n; i++) cout << x[i] << " ";
}
template <typename T>
void prt(T* x, int n) {
  for (int i = 0; i < n; i++) cout << x[i] << " ";
}
template <typename T>
void prtl(vector<T>& x, int n) {
  for (int i = 0; i < n; i++) cout << x[i] << endl;
}
template <typename T>
void prtl(T* x, int n) {
  for (int i = 0; i < n; i++) cout << x[i] << endl;
}
template <typename T>
void scan(T* arr, int n) {
  for (int i = 0; i < n; i++) cin >> arr[i];
}
template <typename T>
void scan(vector<T>& ret, int n) {
  for (int i = 0; i < n; i++) cin >> ret[i];
}
vector<int> failure(string& s) {
  vector<int> f(s.size(), 0);
  int ex = 0;
  for (int i = 1; i < s.size(); i++) {
    while (ex != 0 && s[ex] != s[i]) ex = f[ex - 1];
    if (ex == 0) {
      if (s[ex] != s[i]) {
        f[i] = 0;
        ex = 0;
        continue;
      }
    }
    f[i] = ex + 1;
    ex++;
  }
  return f;
}
long long ans = 0;
vector<vector<int> > q;
int n;
void dfs(int* s, int i, int tot) {
  ans += (s[i] - tot);
  for (int j = 0; j < q[i].size(); j++) dfs(s, q[i][j], s[i]);
}
int main() {
  cin >> n;
  int p[n + 1];
  q.resize(n + 1);
  for (int i = 2; i <= n; i++) cin >> p[i];
  for (int i = 2; i <= n; i++) q[p[i]].push_back(i);
  int s[n + 1];
  for (int i = 1; i <= n; i++) cin >> s[i];
  for (int i = 1; i <= n; i++) {
    if (s[i] != -1) continue;
    int xx = INT_MAX;
    for (int j = 0; j < q[i].size(); j++) {
      xx = min(s[q[i][j]], xx);
    }
    if (xx == INT_MAX)
      s[i] = s[p[i]];
    else
      s[i] = xx;
    if (s[i] < s[p[i]]) {
      cout << -1 << endl;
      return 0;
    }
  }
  dfs(s, 1, 0);
  cout << ans << endl;
}
