#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines class UnionFind: def __init__(self, N): self.root = list(range(N)) self.size = [1] * (N) self.left_end = list(range(N)) self.right_end = list(range(N)) def find_root(self, x): root = self.root while root[x] != x: root[x] = root[root[x]] x = root[x] return x def merge(self, x, y): x = self.find_root(x) y = self.find_root(y) if x == y: return False sx, sy = self.size[x], self.size[y] if sx < sy: self.root[x] = y self.size[y] += sx self.left_end[y] = min(self.left_end[x], self.left_end[y]) self.right_end[y] = max(self.right_end[x], self.right_end[y]) else: self.root[y] = x self.size[x] += sy self.left_end[x] = min(self.left_end[x], self.left_end[y]) self.right_end[x] = max(self.right_end[x], self.right_end[y]) return True D, Q = map(int, readline().split()) m = map(int, read().split()) A, B = zip(*zip(m, m)) B = tuple(b + 1 for b in B) X = sorted(set(A + B)) x_to_i = {v: i for i, v in enumerate(sorted(set(A + B)))} uf = UnionFind(len(X)) find = uf.find_root merge = uf.merge answer = 0 for a, b in zip(A, B): a = x_to_i[a] b = x_to_i[b] a = uf.right_end[find(a)] b = uf.left_end[find(b)] while a < b: merge(a, a + 1) a = uf.right_end[find(a)] b = find(b) width = X[uf.right_end[b]] - X[uf.left_end[b]] if answer < width: answer = width print(answer)