n,m=map(int,input().split()) e={i:set() for i in range(n)} a=set() for _ in range(m): s,l=map(int,input().split()) e[l].add(s) for i in range(n-1, -1, -1): if i not in a:a|=e[i] r=0 for i in a:r|=1<