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;
vector<vector<long long int>> adj(1e6 + 1);
unordered_map<long long int, long long int> vs, mp, mp3, mp2, mp1, vis, mp4;
vector<long long int> vt, vts;
long long int a = 0, k = 0;
double p = 0.0;
void dfs(long long int j) {
  vs[j] = 1;
  for (auto i : adj[j])
    if (!vs[i]) {
      if (mp[i] != -1 && mp[i] < mp1[j])
        a = -1;
      else {
        if (mp[i] == -1) {
          mp1[i] = mp1[j];
          mp2[i] = 0;
        } else {
          mp1[i] = mp[i];
          mp2[i] = mp1[i] - mp1[j];
        }
        k += mp2[i];
      }
      dfs(i);
    }
}
void dfs1(long long int j) {
  vis[j] = 1;
  for (auto i : adj[j])
    if (!vis[i]) {
      if (mp3[j] == 0 && mp4[j] == 0) {
        mp3[j] = mp2[i];
        mp4[j] = 1;
      }
      if (mp2[j] == 0) mp3[j] = min(mp2[i], mp3[j]);
      dfs1(i);
    }
}
void solve() {
  long long int n, x, y, rb1, m;
  cin >> n;
  long long int ar[n];
  for (int i = 1; i < n; i++) {
    cin >> x;
    adj[x].push_back(i + 1);
    adj[i + 1].push_back(x);
  }
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
    mp[i + 1] = ar[i];
  }
  mp1[1] = mp[1];
  k = mp[1];
  dfs(1);
  if (a != -1) {
    dfs1(1);
    for (int i = 0; i < n; i++) {
      if (mp2[i + 1] == 0 && adj[i + 1].size() != 1)
        k = k - (mp3[i + 1] * (adj[i + 1].size() - 2));
    }
    cout << k;
  } else
    cout << a;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  solve();
  return 0;
}
