#!/usr/bin/env python3
import sys


def solve(N: int, M: int, L: "List[int]", R: "List[int]"):
    min = L[0]
    max = R[0]
    for i in range(M):
        if L[i] > min:
            min = L[i]
        if R[i] < max:
            max = R[i]
    ans = 0
    for i in range(1, N+1):
        if min <= i <= max:
            ans += 1
    print(ans)

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    L = [int()] * (M)  # type: "List[int]"
    R = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))
    solve(N, M, L, R)

if __name__ == '__main__':
    main() import sys sys def solve(N: int, M: int, L: "List[int]", R: "List[int]"):
    min = L[0]
    max = R[0]
    for i in range(M):
        if L[i] > min:
            min = L[i]
        if R[i] < max:
            max = R[i]
    ans = 0
    for i in range(1, N+1):
        if min <= i <= max:
            ans += 1
    print(ans)

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template) solve min = L[0] min L[0] L 0 max = R[0] max R[0] R 0 for i in range(M):
        if L[i] > min:
            min = L[i]
        if R[i] < max:
            max = R[i]
     i range(M) range M if L[i] > min:
            min = L[i]
         L[i] > min L[i] L i min min = L[i] min L[i] L i if R[i] < max:
            max = R[i]
     R[i] < max R[i] R i max max = R[i] max R[i] R i ans = 0 ans 0 for i in range(1, N+1):
        if min <= i <= max:
            ans += 1
     i range(1, N+1) range 1 N+1 N 1 if min <= i <= max:
            ans += 1
     min <= i <= max min <= i min i max ans += 1 ans 1 print(ans) print ans return N: int N M: int M L: "List[int]" L R: "List[int]" R def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    L = [int()] * (M)  # type: "List[int]"
    R = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))
    solve(N, M, L, R) main def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
     iterate_tokens for line in sys.stdin:
            for word in line.split():
                yield word
     line sys.stdin sys stdin for word in line.split():
                yield word
     word line.split() line.split line split yield word word tokens = iterate_tokens() tokens iterate_tokens() iterate_tokens N = int(next(tokens)) N int(next(tokens)) int next(tokens) next tokens M = int(next(tokens)) M int(next(tokens)) int next(tokens) next tokens L = [int()] * (M) L [int()] * (M) [int()] int() int M R = [int()] * (M) R [int()] * (M) [int()] int() int M for i in range(M):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))
     i range(M) range M L[i] = int(next(tokens)) L[i] L i int(next(tokens)) int next(tokens) next tokens R[i] = int(next(tokens)) R[i] R i int(next(tokens)) int next(tokens) next tokens solve(N, M, L, R) solve N M L R if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    L = [int()] * (M)  # type: "List[int]"
    R = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))
    solve(N, M, L, R) def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    L = [int()] * (M)  # type: "List[int]"
    R = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))
    solve(N, M, L, R) main def solve(N: int, M: int, L: "List[int]", R: "List[int]"):
    min = L[0]
    max = R[0]
    for i in range(M):
        if L[i] > min:
            min = L[i]
        if R[i] < max:
            max = R[i]
    ans = 0
    for i in range(1, N+1):
        if min <= i <= max:
            ans += 1
    print(ans)

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template) def solve(N: int, M: int, L: "List[int]", R: "List[int]"):
    min = L[0]
    max = R[0]
    for i in range(M):
        if L[i] > min:
            min = L[i]
        if R[i] < max:
            max = R[i]
    ans = 0
    for i in range(1, N+1):
        if min <= i <= max:
            ans += 1
    print(ans)

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template) solve
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, L: "List[int]", R: "List[int]"):
    min = L[0]
    max = R[0]
    for i in range(M):
        if L[i] > min:
            min = L[i]
        if R[i] < max:
            max = R[i]
    ans = 0
    for i in range(1, N+1):
        if min <= i <= max:
            ans += 1
    print(ans)

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    L = [int()] * (M)  # type: "List[int]"
    R = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))
    solve(N, M, L, R)

if __name__ == '__main__':
    main()
