L,M = map(int,input().split()) trees = set(range(L+1)) for _ in range(M): l,r = map(int,input().split()) trees -= set(range(l,r+1)) print(len(trees))