Problem: We have N ID cards, and there are M gates.  We can pass the i-th gate if we have one of the following ID cards: the L_i- th, (L_i+1)-th, ..., and R_i-th ID cards.  How many of the ID cards allow us to pass all the gates alone?

Submission attempts (in order):
# -*- coding: utf-8 -*-
l = [0] 
r = [0]
all_gate_clear = 1


#numcard
N = input()
card_count = range(N+1)

M = input()

for i in range(M):
    l_temp,r_temp = map(int, input().split())
l.append(l_temp)
r.append(r_temp)
    
for gate_num in range(1,M+1):
    
    for card in range(1,N+1):
        num = 0
        while r[gate_num] >= l[gate_num] + num:
            if l[gate_num] + num == card:
                if card_count[card] == gate_num -1:
                    card_count[card] += 1
                    break
            num += 1

for card in range(1,N+1):
    if card_count[card] == M:
        all_gate_clear += 1

print(all_gate_clear)

# -*- coding: utf-8 -*-
l = [0] 
r = [0]
all_gate_clear = 0


#numcard

N, M = map(int, input().split())
card_count = range(N+1)


for i in range(1,M+1):
    l_temp,r_temp = map(int, input().split())
    l.append(l_temp)
    r.append(r_temp)
    
for gate_num in range(1,M+1):
    
    for card in range(1,N+1):
        num = 0
        while r[gate_num] >= l[gate_num] + num:
            if l[gate_num] + num == card:
                if card_count[card] == gate_num -1:
                    card_count[card] += 1
                    break
            num += 1

for card in range(1,N+1):
    if card_count[card] == M:
        all_gate_clear += 1

print(all_gate_clear)

# -*- coding: utf-8 -*-
l = [] 
r = []
count = 0

N, M = map(int, input().split())
l = [0] * N
r = [0] * N
for i in range(0,M):
    l[i], r[i] = map(int, input().split())


    
for i in range(1,N+1):
    if max(l) <= i and i <= min(r):
        count += 1

print(count)

# -*- coding: utf-8 -*-
l = [] 
r = []
count = 0

N, M = map(int, input().split())
l = [0] * N
r = [0] * N
for i in range(0,M):
    l[i], r[i] = map(int, input().split())




    
for i in range(1,N+1):
    if max(l) <= i and i <= min(r):
        count += 1

print(count)

# -*- coding: utf-8 -*-
l = [0] 
r = [0]
all_gate_clear = 1


#numcard

N, M = map(int, input().split())
card_count = range(N+1)


for i in range(M):
    l_temp,r_temp = map(int, input().split())
l.append(l_temp)
r.append(r_temp)
    
for gate_num in range(1,M+1):
    
    for card in range(1,N+1):
        num = 0
        while r[gate_num] >= l[gate_num] + num:
            if l[gate_num] + num == card:
                if card_count[card] == gate_num -1:
                    card_count[card] += 1
                    break
            num += 1

for card in range(1,N+1):
    if card_count[card] == M:
        all_gate_clear += 1

print(all_gate_clear)

# -*- coding: utf-8 -*-
l = []
r = []
all_gate_clear = 0
card_count = []

#numcard
N = input()

M = input()

for i in range(M):
    l[i],r[i] = map(int, input().split())

    
    for gate_num in range(1,M+1):
        
        for card in range(1,N+1):
            for num in range(r[gate_num]+ 1):
                if l[gate_num] + num == card:
                    if card_count[card] == gate_num -1:
                        card_count[card] += 1
                        break

    for card in range(1,N+1):
        if card_count[card] == M:
            all_gate_clear += 1

print(all_gate_clear)

# -*- coding: utf-8 -*-
l = [] 
r = []
all_gate_clear = 0
card_count = []

#numcard
N = input()

M = input()

for i in range(M):
    l_temp,r_temp = map(int, input().split())
    l.append(l_temp)
    r.append(r_temp)

    
    for gate_num in range(1,M+1):
        
        for card in range(1,N+1):
            for num in range(r[gate_num]+ 1):
                if l[gate_num] + num == card:
                    if card_count[card] == gate_num -1:
                        card_count[card] += 1
                        break

    for card in range(1,N+1):
        if card_count[card] == M:
            all_gate_clear += 1

print(all_gate_clear)

# -*- coding: utf-8 -*-
l = [0] 
r = [0]
all_gate_clear = 0
num = 0


#numcard

N, M = map(int, input().split())
card_count = range(N+1)


for i in range(1,M+1):
    l_temp,r_temp = map(int, input().split())
    l.append(l_temp)
    r.append(r_temp)
    
for gate_num in range(1,M+1):
    
    for card in range(1,N+1):
        num = 0
        while r[gate_num] >= l[gate_num] + num:
            if l[gate_num] + num == card:
                if card_count[card] == gate_num -1:
                    card_count[card] += 1
                    break
            num += 1

for card in range(1,N+1):
    if card_count[card] == M:
        all_gate_clear += 1

print(all_gate_clear)

# -*- coding: utf-8 -*-
l = [0] 
r = [0]
all_gate_clear = 0


#numcard

N, M = map(int, input().split())
card_count = range(N+1)


for i in range(M):
    l_temp,r_temp = map(int, input().split())
    l.append(l_temp)
    r.append(r_temp)
    
for gate_num in range(1,M+1):
    
    for card in range(1,N+1):
        num = 0
        while r[gate_num] >= l[gate_num] + num:
            if l[gate_num] + num == card:
                if card_count[card] == gate_num -1:
                    card_count[card] += 1
                    break
            num += 1

for card in range(1,N+1):
    if card_count[card] == M:
        all_gate_clear += 1

print(all_gate_clear)

# -*- coding: utf-8 -*-
l = [] 
r = []
count = 0

N, M = map(int, input().split())
l = [0] * N
r = [0] * N
for i in range(0,N):
    l[i], r[i] = map(int, input().split())


    
for i in range(1,N+1):
    if max(l) <= i and i <= min(r):
        count += 1

print(count)

# -*- coding: utf-8 -*-
l = [0] 
r = [0]
all_gate_clear = 0


#numcard

N, M = map(int, input().split())
card_count = range(1,N+1)


for i in range(1,M+1):
    l_temp,r_temp = map(int, input().split())
    l.append(l_temp)
    r.append(r_temp)
    
for gate_num in range(1,M+1):
    
    for card in range(1,N+1):
        num = 0
        while r[gate_num] >= l[gate_num] + num:
            if l[gate_num] + num == card:
                if card_count[card] == gate_num -1:
                    card_count[card] += 1
                    break
            num += 1

for card in range(1,N+1):
    if card_count[card] == M:
        all_gate_clear += 1

print(all_gate_clear)

# -*- coding: utf-8 -*-
l = [] 
r = []
count = 0

N, M = map(int, input().split())
l = [0] * M
r = [0] * M
for i in range(0,M):
    l[i], r[i] = map(int, input().split())


    
ml = max(l)
mr = min(r)

for i in range(1,N+1):
    if  ml <= i and i <= mr:
        count += 1

print(count)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted