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 int LONG_INT_MAX = 1000000000000005;
long long int mod = 998244353;
long long int mod1 = 1e9 + 7;
struct node {
  int x, y, cost;
};
node getNode(int x, int y, int cost) {
  node n;
  n.x = x;
  n.cost = cost;
  n.y = y;
  return n;
}
class comp {
 public:
  bool operator()(node p1, node p2) { return p1.cost > p2.cost; }
};
long long int gcd(long long int a, long long int b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
long long int extendedEuclid(long long int a, long long int b, long long int& x,
                             long long int& y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  long long int x1, y1, res;
  res = extendedEuclid(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return res;
}
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long int modInverse(long long int n, long long int p) {
  return power(n, p - 2, p);
}
long long int fac[200005];
long long int nCrModPFermat(long long int n, long long int r, long long int p) {
  if (r == 0) return 1;
  return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %
         p;
}
vector<int> adj[200005];
unordered_map<int, long long int> s, f;
long long int fun(int root, int l, long long int w) {
  long long int maxi = -1;
  if (l == 1) {
    for (int i = 0; i < adj[root].size(); i++) {
      int elem = adj[root][i];
      long long int temp = fun(elem, 1 - l, s[root]);
      if (temp == -1) {
        return -1;
      }
      if (maxi == -1) {
        maxi = temp;
      } else {
        maxi = min(maxi, temp);
      }
    }
    if (maxi != -1 && maxi < s[root]) {
      return -1;
    }
    return s[root];
  } else {
    if (adj[root].size() == 0) {
      s[root] = w;
      return w;
    } else {
      long long int mini = -1;
      for (int i = 0; i < adj[root].size(); i++) {
        int elem = adj[root][i];
        long long int temp = fun(elem, 1 - l, -1);
        if (temp == -1) {
          return -1;
        }
        if (mini == -1) {
          mini = temp;
        } else {
          mini = min(mini, temp);
        }
      }
      s[root] = mini;
      return s[root];
    }
  }
}
long long int fun1(int root, long long int w) {
  long long int sum = s[root] - w;
  for (int i = 0; i < adj[root].size(); i++) {
    int elem = adj[root][i];
    sum += fun1(elem, s[root]);
  }
  return sum;
}
int main() {
  int n;
  cin >> n;
  for (int i = 2; i <= n; i++) {
    int elem;
    scanf("%d", &elem);
    adj[elem].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    long long int w;
    cin >> w;
    s[i] = w;
  }
  long long int ans = fun(1, 1, 0);
  if (ans == -1) {
    cout << -1 << endl;
    return 0;
  }
  cout << fun1(1, 0) << endl;
  return 0;
}
