N, M = list(map(int, input().split()))
L, R, flg = 1, N, True
for i in range(M):
    _L, _R = list(map(int, input().split()))
    if L <= _L and _R <= R:
        L = _L
        R = _R
    elif _L <= L and R <= _R:
        continue
    elif L <= _L <= R <= _R:
        L = _L
    elif _L <= L <= _R <= R:
        R = _R
    else:
        flg = False
if flg:
    print(R - L + 1)
else:
    print(0) N, M = list(map(int, input().split())) N list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split M L, R, flg = 1, N, True L 1 R N flg True for i in range(M):
    _L, _R = list(map(int, input().split()))
    if L <= _L and _R <= R:
        L = _L
        R = _R
    elif _L <= L and R <= _R:
        continue
    elif L <= _L <= R <= _R:
        L = _L
    elif _L <= L <= _R <= R:
        R = _R
    else:
        flg = False i range(M) range M _L, _R = list(map(int, input().split())) _L list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split _R if L <= _L and _R <= R:
        L = _L
        R = _R
    elif _L <= L and R <= _R:
        continue
    elif L <= _L <= R <= _R:
        L = _L
    elif _L <= L <= _R <= R:
        R = _R
    else:
        flg = False L <= _L and _R <= R L <= _L L _L _R <= R _R R L = _L L _L R = _R R _R elif _L <= L and R <= _R:
        continue
     _L <= L and R <= _R _L <= L _L L R <= _R R _R continue elif L <= _L <= R <= _R:
        L = _L
     L <= _L <= R <= _R L <= _L <= R L <= _L L _L R _R L = _L L _L elif _L <= L <= _R <= R:
        R = _R
     _L <= L <= _R <= R _L <= L <= _R _L <= L _L L _R R R = _R R _R flg = False flg False if flg:
    print(R - L + 1)
else:
    print(0) flg print(R - L + 1) print R - L + 1 R - L R L 1 print(0) print 0 _R = list(map(int, input().split())) list(map(int, input().split())) _R N, M = list(map(int, input().split())) list(map(int, input().split())) N flg = False False flg R, flg = 1, N, True N R R = _R _R R L = _L _L L L, R, flg = 1, N, True 1 L flg = 1, N, True True flg L = _L _L L M = list(map(int, input().split())) list(map(int, input().split())) M R = _R _R R _L, _R = list(map(int, input().split())) list(map(int, input().split())) _L
N, M = list(map(int, input().split()))
L, R, flg = 1, N, True
for i in range(M):
    _L, _R = list(map(int, input().split()))
    if L <= _L and _R <= R:
        L = _L
        R = _R
    elif _L <= L and R <= _R:
        continue
    elif L <= _L <= R <= _R:
        L = _L
    elif _L <= L <= _R <= R:
        R = _R
    else:
        flg = False
if flg:
    print(R - L + 1)
else:
    print(0)
