import java.util.*;public class Main { public static long ans = 0; public static List list = new ArrayList<>(); public static void main(String args[]) { //4 2 //1 2 3 4 //3 4 2 1 Scanner in = new Scanner(System.in); long n = in.nextLong(); long k = in.nextLong(); Map map = new HashMap<>(); List mark = new ArrayList<>(); for (int i = 0; i long x1 = in.nextLong(); mark.add(x1); } for (int i = 0; i long x2 = in.nextLong(); map.put(mark.get(i), x2); } boolean[] visited = new boolean[(int) n]; dfs(k, map, mark, visited, n,-1); System.out.println(ans); }