import sys if sys.platform =='ios': import clipboard a=clipboard.get() a = a.split('\n') text = '\n'.join(a) with open('input_file.txt','w') as f: f.write(text) sys.stdin = open('input_file.txt') from sys import stdin readline = stdin.readline N, M = map(int, readline().split()) LR = [list(map(int, readline().split())) for _ in range(M)] result = N t = -1 for L, R in sorted(LR, key=lambda x: x[1]): if L <= t <= R: continue result -= 1 t = R print(result)