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
import java.util.*;
import java.io.*;

public class Sol{

static class Pair implements Comparable<Pair>{
        int x;int y;
        public Pair(int x,int y) {
         
          this.x=x;this.y=y;
        }
        @Override
        public int compareTo(Pair p){return Long.compare(y,p.y); }
       
   }

static int n;
static ArrayList<Integer> adj[];static long ans=0l;
static long sum[],a[];static boolean possible=true;
static void dfs(int u,int p,int level){
 
 for(int i:adj[u]){
   if(i==p)continue;
   dfs(i,u,level+1);
    
   if(level%2==0){
        if(sum[u]>=0)sum[u]= Math.min(sum[i],sum[u]);
        else sum[u]=sum[i];
    }
 }
}
static void dfsr(int u,int p,int level){
 if(sum[u]>=0){a[u]=sum[u]-sum[p];} 
 for(int i:adj[u]){
   if(i==p)continue;
   dfsr(i,u,level+1);
 }

}


public static void main(String []args){

int times=1;

while(times-->0){

n=ni();
adj=new ArrayList[n+1];sum=new long[n+1];a=new long[n+1];
for(int i=1;i<=n;i++){adj[i]=new ArrayList<Integer>();}
for(int i=2;i<=n;i++){int u=ni();adj[u].add(i);adj[i].add(u);}
for(int i=1;i<=n;i++){sum[i]=ni();}

dfs(1,0,1);dfsr(1,0,1);
a[1]=sum[1];
for(int i=1;i<=n&&possible;i++){ans+=a[i];if(a[i]<0){possible=false;}}
if(possible)out.println(ans);
else out.println(-1);
}out.close();}

//-----------------Utility--------------------------------------------

static long Comb[][]=new long[405][405];
static long p2[]=new long[405];
static long inv[]=new long[405];
static long factorial[]=new long[405];
static void precomp(){

inv[0]=1;factorial[0]=1l;

for(long i=1;i<405;i++){factorial[(int)i]=i*factorial[(int)i-1];factorial[(int)i]%=mod;}

for(int i=1;i<405;i++){ inv[i]=power(factorial[i],mod-2);}

for(int i=0;i<405;i++){
 
   for(int j=0;j<=i;j++){
     Comb[i][j]=(((factorial[i]*inv[j])%mod)*inv[i-j])%mod;
   }
 }

for(int i=0;i<405;i++)p2[i]=power(2,i);

}

static int Max=Integer.MAX_VALUE; static long mod=1000000007;
static int v(char c){return (int)(c-'a')+1;}
public static long power(long x, long y )
    {
        //0^0 = 1
        long res = 1L;
        x = x%mod;
        while(y > 0)
        {
            if((y&1)==1)
                res = (res*x)%mod;
            y >>= 1;
            x = (x*x)%mod;
        }
        return res;
    }
//--------------------------------------------------------------------

static InputStream inputStream = System.in;
static OutputStream outputStream = System.out;
static FastReader in=new FastReader(inputStream);
static PrintWriter out=new PrintWriter(outputStream);

static class FastReader 
{ 
  BufferedReader br; 
  StringTokenizer st; 
 
        FastReader(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }
 
  public String next() 
  { 
      while (st == null || !st.hasMoreElements()) 
      { 
          try
          { 
              st = new StringTokenizer(br.readLine()); 
          } 
          catch (IOException  e) 
          { 
              e.printStackTrace(); 
          } 
      } 
      return st.nextToken(); 
  } 
 
  public int nextInt() 
  { 
      return Integer.parseInt(next()); 
  } 
 
  public long nextLong() 
  { 
      return Long.parseLong(next()); 
  } 
 
 public  double nextDouble() 
  { 
      return Double.parseDouble(next()); 
  } 
 
 
  String nextLine() 
  { 
      String str = ""; 
      try
      { 
          str = br.readLine(); 
      } 
      catch (IOException e) 
      { 
          e.printStackTrace(); 
      } 
      return str; 
  } 
}
static int ni(){return in.nextInt();}
static long nl(){return in.nextLong();}
static String ns(){return in.nextLine();}
static int[] na(int n){int a[]=new int[n];for(int i=0;i<n;i++){a[i]=ni();} return a;}

}