program sn;
var a:array[1..1000,1..103] of integer;
d:array[0..999] of 0..1;
s,n,i,m,k,l,j:longint;
f,g:text;
procedure Sort(l, r: Integer);
var
i, j, x, y,z,k: integer;
begin
i := l; j := r; x := a[(l+r) DIV 2,1];
repeat
while a[i,1] < x do i := i + 1;
while x < a[j,1] do j := j - 1;
if i <= j then
begin
y := a[i,1]; a[i,1] := a[j,1]; a[j,1] := y;
y := a[i,1]; a[i,1] := a[j,1]; a[j,1] := y;
y := a[i,1]; a[i,1] := a[j,1]; a[j,1] := y;
if a[i,3]>a[j,3] then z:=a[i,3]
else z:=a[j,3];
for k:=1 to z do
y := a[i,3+k]; a[i,3+k] := a[j,3+k]; a[j,3+k] := y;
i := i + 1; j := j - 1;
end;
until i > j;
if l < j then Sort(l, j);
if i < r then Sort(i, r);
end;
begin
assign(f,'aprindere.in');
assign(g,'aprindere.out');
reset(f);
rewrite(g);
readln(f,n,m);
for i:=0 to n-1 do read(f,d[i]); readln(f);
for i:=1 to m do
begin
read(f,a[i,1],a[i,2],a[i,3]);
for j:=1 to a[i,3] do read(f,a[i,j+3]);
end;
sort(1,m);
s:=0;
for i:=1 to m do
if d[a[i,1]]<>1 then
begin
s:=s+a[i,2];
for j:=4 to a[i,3]+3 do
if d[a[i,j]]=0 then
d[a[i,j]]:=1
else d[a[i,j]]:=0;
end;
close(f);writeln(g,s);
close(G);
end.