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;
inline char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline long long read() {
  char c = getchar();
  long long tot = 1;
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') {
    tot = -1;
    c = getchar();
  }
  long long sum = 0;
  while (c >= '0' && c <= '9') {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  return sum * tot;
}
inline void wr(long long x) {
  if (x < 0) {
    putchar('-');
    wr(-x);
    return;
  }
  if (x >= 10) wr(x / 10);
  putchar(x % 10 + '0');
}
inline void wrn(long long x) {
  wr(x);
  putchar('\n');
}
inline void wri(long long x) {
  wr(x);
  putchar(' ');
}
inline void wrn(long long x, long long y) {
  wri(x);
  wrn(y);
}
inline void wrn(long long a, long long b, long long c) {
  wri(a);
  wrn(b, c);
}
long long n, m, ans, b[500055], fa[500055];
long long nedge, head[500055 * 2], to[500055 * 2], Next[500055 * 2];
void add(long long a, long long b) {
  Next[++nedge] = head[a];
  head[a] = nedge;
  to[nedge] = b;
}
void add_ne(long long a, long long b) {
  add(a, b);
  add(b, a);
}
void solve(long long x) {
  long long pd = 0;
  if (b[x] == -1) {
    pd = 1;
    b[x] = 1000000005;
  }
  for (long long i = head[x]; i; i = Next[i]) {
    if (pd) b[x] = min(b[x], b[to[i]]);
    fa[to[i]] = x;
    solve(to[i]);
  }
  if (b[x] == 1000000005) b[x] = b[fa[x]];
}
void dfs(long long x) {
  if (b[x] < b[fa[x]]) {
    puts("-1");
    exit(0);
  }
  ans += b[x] - b[fa[x]];
  for (long long i = head[x]; i; i = Next[i]) {
    fa[to[i]] = x;
    dfs(to[i]);
  }
}
signed main() {
  n = read();
  for (long long i = (2); i <= (n); i++) add(read(), i);
  for (long long i = (1); i <= (n); i++) b[i] = read();
  solve(1);
  dfs(1);
  wrn(ans);
  return 0;
}
