n,m=map(int,input().split()) e=[] for i in range(m): a,b=map(int,input().split()) e+=[(a-1,b-1)] def root(x): p=x l=[p] while r[p]!=p: p=r[p] l+=[p] for p in l: r[p]=l[-1] return r[x] def union(x,y): rx=root(x) ry=root(y) if rx==ry: return if rx>ry: rx,ry=ry,rx r[ry]=rx return r=list(range(n)) for a,b in e: union(a,b) c1=sum(root(i)==i for i in range(n)) c1-=c1==1 class SCC(): def __init__(self,n): self.n=n self.e=[[] for i in range(self.n)] self.re=[[] for i in range(self.n)] return def add_edge(self,s,t): self.e[s]+=[t] self.re[t]+=[s] return def scc(self): v=[0]*self.n g=[0]*self.n o=[] for i in range(self.n): if v[i]==0: q=[i] while len(q)>0: s=q[-1] v[s]=1 while g[s]0: for t in E[s]: if v[t]==0: v[t]=1 f[t]+=1 else: f[s]+=1 c2=sum(f[i]==2 for i in range(l)) print(c1+c2)