import java.util.*;public class Main {public static long ans = 0;public static List<Long> list = new ArrayList<>();public static void main(String args[]) {//4 2//1 2 3 4//3 4 2 1Scanner in = new Scanner(System.in);long n = in.nextLong();long k = in.nextLong();Map<Long, Long> map = new HashMap<>();List<Long> mark = new ArrayList<>();for (int i = 0; i < n; i++) {long x1 = in.nextLong();mark.add(x1);}for (int i = 0; i < n; 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);}