N, M = map(int, input().split())
L, R = map(int, input().split())


for i in range(M-1):
      L1, R1 = map(int, input().split())
      if R1 < L or R < L1:
        print(0)
        exit()
      else:
        if L <= L1 <= R:
          L = L1
          
        elif L <= R1 <= R:
          R = R1
        
          
print(R-L+1) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L, R = map(int, input().split()) L map(int, input().split()) map int input().split() ().split () input split R for i in range(M-1):
      L1, R1 = map(int, input().split())
      if R1 < L or R < L1:
        print(0)
        exit()
      else:
        if L <= L1 <= R:
          L = L1
          
        elif L <= R1 <= R:
          R = R1
        
           i range(M-1) range M-1 M 1 L1, R1 = map(int, input().split()) L1 map(int, input().split()) map int input().split() ().split () input split R1 if R1 < L or R < L1:
        print(0)
        exit()
      else:
        if L <= L1 <= R:
          L = L1
          
        elif L <= R1 <= R:
          R = R1
        
           R1 < L or R < L1 R1 < L R1 L R < L1 R L1 print(0) print 0 exit() exit if L <= L1 <= R:
          L = L1
          
        elif L <= R1 <= R:
          R = R1
        
           L <= L1 <= R L <= L1 L L1 R L = L1 L L1 elif L <= R1 <= R:
          R = R1
        
           L <= R1 <= R L <= R1 L R1 R R = R1 R R1 print(R-L+1) print R-L+1 R-L R L 1 L, R = map(int, input().split()) map(int, input().split()) L N, M = map(int, input().split()) map(int, input().split()) N R1 = map(int, input().split()) map(int, input().split()) R1 R = R1 R1 R R = map(int, input().split()) map(int, input().split()) R L = L1 L1 L M = map(int, input().split()) map(int, input().split()) M L1, R1 = map(int, input().split()) map(int, input().split()) L1
N, M = map(int, input().split())
L, R = map(int, input().split())


for i in range(M-1):
      L1, R1 = map(int, input().split())
      if R1 < L or R < L1:
        print(0)
        exit()
      else:
        if L <= L1 <= R:
          L = L1
          
        elif L <= R1 <= R:
          R = R1
        
          
print(R-L+1)