import std.stdio, std.conv, std.array, std.string;
import std.algorithm;
import std.container;
import std.range;
import core.stdc.stdlib;
import std.math;
import std.regex;
 
struct Key {
  int id;
  int price;
  int[] canOpen;
}
 
void main() {
  int N, M; readf("%d %d\n", &N, &M);
 
  Key[] keys;
  foreach(z; 0..M) {
    int price, canOpenCount; readf("%d %d\n", &price, &canOpenCount);
    Key key = Key();
    key.price = price;
    key.canOpen = readln.split.to!(int[]);
    key.id = z;
    keys ~= key;
  }
 
  int[] openCount = new int[N];
  keys.each!(k => k.canOpen.each!(n => openCount[n-1]++));
  debug openCount.writeln;
  
  if (openCount.any!("a == 0")) {
    writeln("-1");
    exit(0);
  }
  
  int[][] duplicates;
  foreach(i; 0..N) {
    if (openCount[i] <= 1) continue;
 
    duplicates ~= [i+1, openCount[i]];
  }
  debug writeln(duplicates);
 
  bool[] removeList = new bool[M];
  debug removeList.writeln();
  foreach(z; 0..M) {
    if (duplicates.empty) break;
    auto duplicateNumbers = duplicates.map!(d => d[0]);
 
    debug duplicates.writeln();
 
    Key keyToRemove;
    foreach(key; keys) {
      if (removeList[key.id]) continue;
      if (key.canOpen.any!(o => !duplicateNumbers.canFind(o))) continue;
 
      if (keyToRemove.price == 0 || keyToRemove.price < key.price) keyToRemove = key;
    }
 
    if (keyToRemove.price == 0) break;
 
    removeList[keyToRemove.id] = true;
    foreach(i; keyToRemove.canOpen) {
      foreach(d; duplicates) {
        if (d[0] == i) d[1]--;
      }
      duplicates = duplicates.filter!(d => d[1] > 1).array;
    }
  }
 
  int sum = 0;
  foreach(key; keys) {
    if (!removeList[key.id]) sum += key.price;
  }
  writeln(sum);
}
