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

min, max = map(int, input().split())

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

min, max = map(int, input().split())

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