n, m = map(int, input().split()) r = [] for i in range(m): r.append(list(map(int,input().split()))) r.sort() r.sort(key = lambda x : x[1]) cnt = 0 z = -1 for x in r: if z < x[0]: cnt += 1 z = x[1] print(n - cnt)