N, M = map(int, input().split()) data = [] for i in range(M): l,r = map(int, input().split()) data.append([l, r]) data.sort(key=lambda x:x[1]) cnt = 1 pre = data[0][1] for i in range(1, M): if pre < data[i][0]: cnt += 1 pre = data[i][1] print(N-cnt)