def main():

  IN= open(0).read().split()[2:]

  left,right=-1*float("inf"),float("inf")

  

  for L,R in zip(IN[::2],IN[1::2]):

    L,R=int(L),int(R)

    if right<L or R<left:

      print((0))

      break

    else:

      tmp=sorted([left,right,L,R])

      left,right=tmp[1],tmp[2]

  else:

    print((right-left+1))

  

if __name__=="__main__":

  main()
def main():

  IN=list(map(int,open(0).read().split()[2:]));L,R=max(IN[::2]),min(IN[1::2]);print((R-L+1 if R>=L else 0))

if __name__=="__main__":

  main()
def main():
    IN = open(0).read().split()[2:]
    left, right = -1 * float("inf"), float("inf")
    for L, R in zip(IN[::2], IN[1::2]):
        L, R = int(L), int(R)
        if right < L or R < left:
            print((0))
            break
        else:
            tmp = sorted([left, right, L, R])
            left, right = tmp[1], tmp[2]
    else:
        print((right - left + 1))


if __name__ == "__main__":
    main()

def main():
    IN = list(map(int, open(0).read().split()[2:]))
    L, R = max(IN[::2]), min(IN[1::2])
    print((R - L + 1 if R >= L else 0))


if __name__ == "__main__":
    main()

-    IN = open(0).read().split()[2:] -    left, right = -1 * float("inf"), float("inf") -    for L, R in zip(IN[::2], IN[1::2]): -        L, R = int(L), int(R) -        if right < L or R < left: -            print((0)) -            break -        else: -            tmp = sorted([left, right, L, R]) -            left, right = tmp[1], tmp[2] -    else: -        print((right - left + 1)) +    IN = list(map(int, open(0).read().split()[2:])) +    L, R = max(IN[::2]), min(IN[1::2]) +    print((R - L + 1 if R >= L else 0))