int1 = lambda x: int(x) - 1 N, M = map(int, input().split()) table = [None] * N for _ in range(M): g, r = map(int, input().split()) h = set(map(int1, input().split())) g -= 1 table[g] = h basket = set(i for i, t in enumerate(table) if t is None) ans = len(basket) while True: for i in range(N): if i not in basket: if table[i] <= basket: basket.add(i) if ans == len(basket): print(ans) break else: ans = len(basket)