import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

N, M = map(int, input().split())
maxL = 1
minR = N
for _ in range(M):
    L, R = map(int, input().split())
    maxL = max(maxL, L)
    minR = min(minR, R)
ans = minR - maxL + 1
ans = max(ans, 0)
print(ans) import sys sys readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline readlines = sys.stdin.buffer.readlines readlines sys.stdin.buffer.readlines sys.stdin.buffer sys.stdin sys stdin buffer readlines read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read sys.setrecursionlimit(10 ** 7) sys.setrecursionlimit sys setrecursionlimit 10 ** 7 10 7 INF = float('inf') INF float('inf') float 'inf' N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M maxL = 1 maxL 1 minR = N minR N for _ in range(M):
    L, R = map(int, input().split())
    maxL = max(maxL, L)
    minR = min(minR, R) _ range(M) range M L, R = map(int, input().split()) L map(int, input().split()) map int input().split() ().split () input split R maxL = max(maxL, L) maxL max(maxL, L) max maxL L minR = min(minR, R) minR min(minR, R) min minR R ans = minR - maxL + 1 ans minR - maxL + 1 minR - maxL minR maxL 1 ans = max(ans, 0) ans max(ans, 0) max ans 0 print(ans) print ans maxL = 1 1 maxL L, R = map(int, input().split()) map(int, input().split()) L M = map(int, input().split()) map(int, input().split()) M ans = max(ans, 0) max(ans, 0) ans minR = N N minR readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline read = sys.stdin.buffer.read sys.stdin.buffer.read read readlines = sys.stdin.buffer.readlines sys.stdin.buffer.readlines readlines maxL = max(maxL, L) max(maxL, L) maxL minR = min(minR, R) min(minR, R) minR N, M = map(int, input().split()) map(int, input().split()) N R = map(int, input().split()) map(int, input().split()) R INF = float('inf') float('inf') INF ans = minR - maxL + 1 minR - maxL + 1 ans
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

N, M = map(int, input().split())
maxL = 1
minR = N
for _ in range(M):
    L, R = map(int, input().split())
    maxL = max(maxL, L)
    minR = min(minR, R)
ans = minR - maxL + 1
ans = max(ans, 0)
print(ans)