#include #include #define rep(i,n) for(int i=0;i vi; typedef vector vl; typedef vector> vvi; typedef vector> vvl; typedef long double ld; typedef pair P; ostream& operator<<(ostream& os, const modint& a) {os << a.val(); return os;} template ostream& operator<<(ostream& os, const static_modint& a) {os << a.val(); return os;} template ostream& operator<<(ostream& os, const dynamic_modint& a) {os << a.val(); return os;} template istream& operator>>(istream& is, vector& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;} template ostream& operator<<(ostream& os, const pair& p){os << p.first << ' ' << p.second; return os;} template ostream& operator<<(ostream& os, const vector& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;} template ostream& operator<<(ostream& os, const vector>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;} template void chmin(T& a, T b){a = min(a, b);} template void chmax(T& a, T b){a = max(a, b);} const long long INF = 1001001001001001; int main(){ int n, m; cin >> n >> m; vector a(n); cin >> a; vector b(m); cin >> b; mf_graph graph(n + m + 2); int sv = n + m; int tv = n + m + 1; rep(i, n){ graph.add_edge(sv, i, a[i]); } long long ans = 0; rep(i, m){ int dummy = n + i; ans += b[i]; graph.add_edge(dummy, tv, b[i]); int k; cin >> k; rep(j, k){ int x; cin >> x; x--; graph.add_edge(x, dummy, INF); } } ans -= graph.flow(sv, tv); cout << ans << "\n"; return 0; }