def solver(total, current, card): global answer if tuple(sorted(card)) in memo: return memo.add(tuple(sorted(card))) answer = max(answer, total) for x in range(N): if x in card: card.remove(x) total += A[x] deletes = current.intersection(inv_cards[x]) for delete in deletes: total -= B[delete] current.remove(delete) rem = [] for y in range(N): if y in card and not current.intersection(inv_cards[y]): card.remove(y) total += A[y] rem.append(y) solver(total, current, card) for y in rem: card.add(y) total -= A[y] for delete in deletes: total += B[delete] current.add(delete) total -= A[x] card.add(x) N, M = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) cards = [list(map(lambda x: int(x)-1, input().split()))[1:] for _ in range(M)] inv_cards = [set() for _ in range(N)] for x in range(M): for c in cards[x]: inv_cards[c].add(x) memo = set() answer = max(sum(B) - sum(A), 0) solver(answer, set(range(M)), set(range(N))) print(answer)