N,Q = list(map(int,input().split())) dat = [0] * (Q+2) for i in range(Q): l,r = list(map(int,input().split())) dat[l] += 1 dat[r+1] -= 1 count = 0 for i in range(1,Q+1): dat[i] += dat[i-1] if dat[i] % 2 == 1:count += 1 print(count)