#include <fstream>
using namespace std;
ifstream fin ("aprindere.in");
ofstream fout ("aprindere.out");
#define NMAX 1005
int n, m, stinse, a[NMAX], b[NMAX], cam, t, kcam, tmin;
int main ()
{
fin >> n >> m;
for (int i = 0; i <= n - 1; ++i)
{
fin >> a[i];
if (a[i] == 0) ++stinse;
}
for (int i = 1; i <= m; ++i)
{
fin >> cam >> t >> kcam;
for (int j = 1; j <= kcam; ++j)
fin >> b[j];
if (a[cam] == 0)
{
tmin += t;
for (int j = 1; j <= kcam; ++j)
{
if (a[b[j]] == 0)
{
a[b[j]] = 1;
--stinse;
}
else
{
a[b[j]] = 0;
++stinse;
}
}
}
if (stinse == 0) break;
}
fout << tmin;
fin.close (); fout.close ();
return 0;
}