program dsfhdfsg;
var a,b,c,q,w:array[0..1000]of longint;
d,n,e,f,x,y,u,i,o:longint;
begin
assign(input,'riddle.in');
reset(input);
assign(output,'riddle.out');
rewrite(output);
readln(a[1]);
readln(n);
for d:=2 to n do a[d]:=a[1];
for d:=1 to n do read(b[d]); readln;
for d:=1 to n do read(c[d]);readln;
for x:=1 to n-1 do
for y:=x+1 to n do
if c[x]<c[y] then
begin
e:=b[x];b[x]:=b[y];b[y]:=e;
f:=c[x];c[x]:=c[y];c[y]:=f;
end;
q[0]:=1000;
for d:=1 to n do
begin
if q[b[d]]=0 then begin q[b[d]]:=d;end else
if q[b[d]]<>0 then
for u:=b[d]-1 downto 0 do
begin
if q[u]=0 then begin q[u]:=d;break;end;
if q[u]=1000 then a[1]:=a[1]-c[d];end;
end;
write(a[1]);
close(input);
close(output);
end.