#include <fstream>
using namespace std;
#define in "aprindere.in"
#define out "aprindere.out"
#define NMAX 1001
typedef struct nod {
int vf;
nod *next;
} *PNOD, NOD;
PNOD L[NMAX];
int n, m,best;
int stare[NMAX];
int tor[NMAX];
int timp[NMAX];
FILE *fout = fopen ( out, "w" );
void Add(int,int);
void Add( int i, int j )
{
PNOD p = new NOD;
p->vf = j;
p->next = L[i];
L[i] = p;
}
int main()
{
FILE *fin = fopen ( in, "r" );
fscanf( fin, "%d%d", &n, &m );
int i,nr,cam,temp,val,j;
for ( i = 0; i < n; ++i )
fscanf( fin, "%d", &stare[i] );
for ( i = 1; i <= m; ++i )
{
fscanf( fin, "%d%d%d", &cam, &temp, &nr );
timp[cam] = temp;
tor[cam] = 1;
for ( j = 1; j <= nr; ++j )
{
fscanf( fin, "%d", &val );
Add ( cam, val );
}
}
//fprintf ( fout, "Am actionat intrerupatoarele " );
for ( i = 0; i < n; ++i )
{
if ( stare[i] == 0 )
{
if ( tor[i] )
{
best += timp[i];
// fprintf( fout, "%d ", i );
for ( PNOD p = L[i]; p; p = p->next )
{
if ( stare[p->vf] == 0 ) stare[p->vf] = 1;
else if ( stare[p->vf] == 1 ) stare[p->vf] = 0;
}
}
}
}/*
fprintf ( fout, "\n" );
for ( i = 1; i <= n; ++i )
fprintf ( fout, "%d ", stare[i] );
fprintf( fout, "\n" );
for ( i = 1; i <= n; ++i )
fprintf ( fout, "%d ", timp[i] );
fprintf( fout, "\n" );
for ( i = 1; i <= n; ++i )
{
fprintf( fout, "%d: ", i );
for ( PNOD p = L[i]; p; p = p->next )
fprintf( fout, "%d ", p->vf );
fprintf ( fout, "\n" );
}
fprintf ( fout, "\n" );
*/
fprintf( fout, "%d\n", best );
fclose ( fin );
fclose ( fout );
return 0;
}