n,m = map(int,input().split()) goods = [[]for i in range(n+1)] def search(i): if goods[i]==-1: return False else: tmp = goods[i][:] goods[i] = -1 for j in tmp: if search(j):goods[j]=[] else: return False return True for i in range(m): g,r = map(int,input().split()) h = list(map(int,input().split())) goods[g] = h cnt = 0 for i in range(1,n+1): if search(i): goods[i] = [] else: cnt+=1 print(n-cnt)