N,M = map(int,input().split()) D = [list(map(int,input().split())) for _ in range(M)] for i in range(M): D[i][0] = N-D[i][0] D[i][1] = N-D[i][1]+1 d = [] for l,r in D: d.append((l,0)) d.append((r,1)) d.sort(reverse=True) ans = 0 for i in range(N): while d[-1][0]==i: if d[-1][1] == 0: ans += 1 else: ans -= 1 d.pop() print(ans)