import java.io.*;
import java.util.*;
import java.math.*;

public class project_aa_na {
	public static void main(String[] args) {
		new project_aa_na().run();
	}

	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	boolean eof = false;

	public void run() {
		Locale.setDefault(Locale.US);
		try {
			br = new BufferedReader(new FileReader(FNAME + ".in"));
			out = new PrintWriter(FNAME + ".out");
			solve();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(566);
		}
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return "0";
			}
		}
		return st.nextToken();
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	String FNAME = "project";

	private void solve() throws IOException {
		int n = nextInt();
		k = nextInt();
		t = new int[n];
		for (int i = 0; i < t.length; i++) {
			t[i] = nextInt();
		}
		int[] p = new int[n - 1];
		for (int i = 0; i < p.length; i++) {
			p[i] = nextInt() - 1;
		}
		int[] ch = new int[n];
		for (int i : p) {
			ch[i]++;
		}
		g = new int[n][];
		for (int i = 0; i < g.length; i++) {
			g[i] = new int[ch[i]];
		}
		for (int i = 0; i < p.length; i++) {
			g[p[i]][--ch[p[i]]] = i + 1;
		}
		a = new int[n][];
		d = new int[n];
		dfs(0);
		out.println(a[0][k]);
	}

	int[] t;

	int[][] a;
	int[] d;
	int k;

	private void dfs(int x) {
		int ch = g[x].length;
		int[][] c = new int[ch + 1][k + 1];
		for (int i = 0; i < c.length; i++) {
			Arrays.fill(c[i], Integer.MAX_VALUE / 2);
		}
		d[x] = 1;
		for (int i : g[x]) {
			dfs(i);
			d[x] += d[i];
		}
		c[0][0] = 0;
		for (int i = 0; i + 1 < c.length; i++) {
			for (int j = 0; j < c[i].length; j++) {
				if (c[i][j] < Long.MAX_VALUE / 2) {
					for (int q = 0; q + j <= k; q++) {
						c[i + 1][j + q] = Math.min(c[i + 1][j + q], c[i][j]
								+ a[g[x][i]][q]);
					}
				}
			}
		}
		a[x] = new int[k + 1];
		Arrays.fill(a[x], Integer.MAX_VALUE / 2);
		for (int i = 0; i < c[ch].length; i++) {
			a[x][i] = Math.min(a[x][i], c[ch][i]);
		}
		if (d[x] <= k) {
			a[x][d[x]] = Math.min(a[x][d[x]], a[x][d[x] - 1] + t[x]);
		}
	}

	int[][] g;
}
