def toggle(on: int) -> int: return 1 - on def main(): n, q = map(int, input().split()) cnt = 0 lamps = [0] * n for _ in range(q): l, r = map(int, input().split()) for i in range(l, r + 1): on_off = toggle(lamps[i - 1]) if on_off == 0: cnt -= 1 else: cnt += 1 lamps[i - 1] = on_off print(cnt) if __name__ == "__main__": main()