from collections import deque class mf_graph: n=1 g=[[] for i in range(1)] pos=[] def __init__(self,N): self.n=N self.g=[[] for i in range(N)] self.pos=[] def add_edge(self,From,To,cap): assert 0<=From and From=0:continue level[to]=level[v]+1 if to==t:return level que.append(to) return level def dfs(v,up): if (v==s):return up res=0 level_v=level[v] for i in range(Iter[v],len(self.g[v])): Iter[v]=i to,rev,cap=self.g[v][i] if (level_v<=level[to] or self.g[to][rev][2]==0):continue d=dfs(to,min(up-res,self.g[to][rev][2])) if d<=0:continue self.g[v][i][2]+=d self.g[to][rev][2]-=d res+=d if res==up:return res level[v]=self.n return res flow=0 while(flow0): p=que.popleft() visited[p]=True for to,rev,cap in self.g[p]: if cap and not(visited[to]): visited[to]=True que.append(to) return visited n,m = map(int,input().split()) a = list(map(int,input().split())) b = list(map(int,input().split())) g = mf_graph(n+m+2) ans = 0 for i in range(m): q = list(map(int,input().split())) ans += b[i] g.add_edge(n+m,n+i,b[i]) g.add_edge(n+i,n+m+1,0) for k in range(1,len(q)): g.add_edge(n+i,q[k]-1,10**18) for i in range(n): g.add_edge(i,n+m+1,a[i]) print(-(g.flow(n+m,n+m+1,10**18) - ans))