#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
const int Nmax = 1002;
vector <int> G[Nmax];
int state[Nmax], time[Nmax];
int timp;
int N, M;
int main()
{
ifstream f("aprindere.in");
ofstream g("aprindere.out");
f >> N >> M;
for ( int i = 1; i <= N; ++i )
f >> state[i];
for ( int i = 1, ind, nrc, val; i <= M; ++i )
{
f >> ind;
ind++;
f >> time[ ind ];
f >> nrc;
for ( int j = 1; j <= nrc; ++j )
{
f >> val;
val++;
G[ind].push_back( val );
}
}
for ( int i = 1; i <= N; ++i )
{
if ( state[i] == 0 )
{
timp += time[i];
for ( auto x: G[i] )
state[ x ] ^= 1;
}
}
g << timp << "\n";
return 0;
}