Language: C++

/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <fstream>
#include <iostream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <ext/random>
#include <ext/rope>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using ull = unsigned long long;
using vi = std::vector<int>;
using vl = std::vector<int64>;
using pii = std::pair<int, int>;
using pii = std::pair<int, int>;
using pll = std::pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(_) (_).begin(), (_).end()
#define rall(_) (_).rbegin(), (_).rend()
#define print(_) std::cout << (_) << '\n'
#define debug(_) std::cerr << #_ << ": " << (_) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
template<typename T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  os << '{';
  for (size_t i = 0; i < vec.size(); ++i) {
    os << vec[i];
    if (i != vec.size() - 1) os << ',';
  }
  os << '}';
  return os;
}
template<typename T, typename U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '{' << p.first << " " << p.second << '}';
}
// constant
const int INF = (1<<30) - 1;  // 1.073741823e9
const int64 INF64 = (1LL<<62) - 1;  // 4.611686018427387903e18
const int MOD = 1000000007;

struct key {
  int64 cost;
  vector<int64> open;
};


int main(){
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int64 n, m; cin >> n >> m;
  vector<key> vec;

  int64 sum = 0;

  rep(i, m) {
    int a, b; cin >> a >> b;
    sum += a;
    vector<int> v;
    rep(j, b) {
      int c; cin >> c;
      v.emplace_back(c);
    }
    vec.push_back({a, v});
  }

  sort(all(vec), [](const key& x, const key& y){
    return x.cost > y.cost;
  });
/*
  rep(i, m) {
    cerr << vec[i].cost << " ";
    debug(vec[i].open);
  }
*/
  map<int64, int64> mp;
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < (int) vec[i].open.size(); ++j) {
      ++mp[vec[i].open[j]];
    }
  }

  for (int i = 1; i <= n; ++i) {
    if (mp[i] == 0LL) {
      cout << -1 << '\n'; return 0;
    }
  }
/*
  for (auto x : mp) {
    debug(x);
  }
*/
/*
  for (int i = 0; i < m; ++i) {
    bool flag = true;
    for (auto it = mp.begin(); it != mp.end(); ++it) {
      for (int j = 0; j < (int) vec[i].open.size(); ++j) {
        if (mp[vec[i].open[j]] < 2) {
          flag = false;
          break;
        }
      }
      if (flag) {
        for (int j = 0; j < (int) vec[i].open.size(); ++j) {
          --mp[vec[i].open[j]];
        }
        sum -= vec[i].cost;
      }
    }
  }
*/
  //debug(sum);

  for (int i = 0; i < m; ++i) {
    bool flag = true;
    for (int j = 0; j < (int) vec[i].open.size(); ++j) {
      if (mp[vec[i].open[j]] < 2) {
        flag = 0;
        break;
      } 
    }
    if (flag) {
      for (int j = 0; j < (int) vec[i].open.size(); ++j) {
        if (mp[vec[i].open[j]] == 0) continue;
        else --mp[vec[i].open[j]];
      }
      sum -= vec[i].cost;
    }
  }

  cout << sum << endl;

  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:99:18: error: no matching function for call to 'std::vector<key>::push_back(<brace-enclosed initializer list>)'
   99 |     vec.push_back({a, v});
      |     ~~~~~~~~~~~~~^~~~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/queue:63,
                 from a.cc:15:
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = key; _Alloc = std::allocator<key>; value_type = key]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<key>::value_type&' {aka 'const key&'}
 1283 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = key; _Alloc = std::allocator<key>; value_type = key]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<key>::value_type&&' {aka 'key&&'}
 1300 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~