N,M = map(int,input().split()) graph = [[] for i in range(N)] p = [list(map(int,input().split())) for i in range(M)] p = sorted(p,reverse=True) ans = 0 s = set() for i in range(M): if p[i][1] in s: continue s.add(p[i][0]) for i in s: ans += (1<