uses math;
var
maxx,n,i,m,kk,i1,i2,i3,i4:longint;
k:array[0..4] of integer;
f:array[-4..5,-1..40,-1..40,-1..40] of longint;
a:array[0..351] of longint;
b:array[0..121] of longint;
begin
readln(n,m);
for i:=1 to n do read(a[i]);readln;
for i:=1 to m do begin
read(b[i]);
inc(k[b[i]]);
end;
f[1,0,0,0]:=a[1];
for i:=2 to 4 do begin
for i1:=0 to k[1] do if i1<=3 then
for i2:=0 to k[2] do begin
if i1+i2*2+1>i then break;
for i3:=0 to k[3] do begin
if i1+i2*2+i3*3+1>i then break;
if (i-i1-i2*2-i3*3-1) mod 4<>0 then continue;
i4:=(i-i1-i2*2-i3*3-1) div 4;
if i4>k[4] then continue;
f[i,i1,i2,i3]:=a[i]+max(
max(f[i-3,i1,i2,i3-1],f[i-4,i1,i2,i3]),max(f[i-1,i1-1,i2,i3],f[i-2,i1,i2-1,i3]));
if i=n then if f[i,i1,i2,i3]>maxx then maxx:=f[i,i1,i2,i3];
end;
end;
end;
for i:=5 to n do begin
for i1:=0 to k[1] do begin
if i1+1>i then break;
for i2:=0 to k[2] do begin
if i1+i2*2+1>i then break;
for i3:=0 to k[3] do begin
if i1+i2*2+i3*3+1>i then break;
if (i-i1-i2*2-i3*3-1) mod 4<>0 then continue;
i4:=(i-i1-i2*2-i3*3-1) div 4;
if i4>k[4] then continue;
f[5,i1,i2,i3]:=a[i]+max(
max(f[2,i1,i2,i3-1],f[1,i1,i2,i3]),max(f[4,i1-1,i2,i3],f[3,i1,i2-1,i3]));
if i=n then if f[5,i1,i2,i3]>maxx then maxx:=f[5,i1,i2,i3];
end;
end;
end;
for kk:=1 to 4 do f[kk]:=f[kk+1];
end;
writeln(maxx);
end.