import heapq n = int(input()) lr = [tuple(map(int, input().split())) for _ in range(n)] def get_min_k(): lr.sort() k = max(lr[i][0] - (i + 1) for i in range(n)) pq = [] j = 0 for v in range(k + 1, k + n + 1): while j < n and lr[j][0] <= v: heapq.heappush(pq, lr[j][1]) j += 1 if pq[0] < v: return None heapq.heappop(pq) return k M = 10 ** 9 + 1 min_k = get_min_k() if min_k is None: print(0) else: lr = [(M - r, M - l) for l, r in lr] max_k = get_min_k() assert max_k is not None max_k = M - max_k - (n + 1) print(max_k - min_k + 1)