#yuki_479 n,m=map(int,raw_input().split()) g=[] for i in xrange(m): a,b=map(int,raw_input().split()) g.append([a,b]) g.sort() g.reverse() l=[] for i in xrange(m): if g[i][1] in l: continue l.append(g[i][0]) s=set(l) res=0 for i in s: res+=1<