Buggy python submission (verdict: Time Limit Exceeded):
import sys
args = sys.stdin.readlines()
n, m = map(int, args[0].split(' '))
ids = set(range(1, n+1))

for gate in args[1:]:
  l, r = map(int, gate.split(' '))  
  ids = ids & set(range(l, r+1))
  
print(len(ids))


Fixed submission:
import sys
args = sys.stdin.readlines()
n, m = map(int, args[0].split(' '))
l_1 = 1
r_1 = n

for gate in args[1:]:
  l, r = map(int, gate.split(' '))  
  if l > l_1:
    l_1 = l
  if r < r_1:
    r_1 = r

ids = r_1 - l_1 + 1
if ids < 0:
  print(0)
else:
  print(ids)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
args = sys.stdin.readlines()
n, m = map(int, args[0].split(' '))
gates = []
for gate in args[1:]:
  l, r = map(int, gate.split(' '))
  gates.append((l, r))
  
ids = set(range(1, n+1))
for gate in gates:
  l, r = gate
  ids = ids & set(range(l, r+1))
  
print(len(ids))


Fixed submission:
import sys
args = sys.stdin.readlines()
n, m = map(int, args[0].split(' '))
l_1 = 1
r_1 = n

for gate in args[1:]:
  l, r = map(int, gate.split(' '))  
  if l > l_1:
    l_1 = l
  if r < r_1:
    r_1 = r

ids = r_1 - l_1 + 1
if ids < 0:
  print(0)
else:
  print(ids)

Buggy python submission (verdict: Runtime Error):
import sys
args = sys.stdin.readlines()
n, m = map(int, args[0].split(' '))
gates = []
for gate in args[1:]:
  l, r = map(int, gate.split(' '))
  gates.append((l, r))
  
ids = gates[0]
for gate in gates[1:]:
  l, r = gate
  ids = ids[l-ids[0]:r-ids[-1]+1]
  
print(len(ids))


Fixed submission:
import sys
args = sys.stdin.readlines()
n, m = map(int, args[0].split(' '))
l_1 = 1
r_1 = n

for gate in args[1:]:
  l, r = map(int, gate.split(' '))  
  if l > l_1:
    l_1 = l
  if r < r_1:
    r_1 = r

ids = r_1 - l_1 + 1
if ids < 0:
  print(0)
else:
  print(ids)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
args = sys.stdin.readlines()
n, m = map(int, args[0].split(' '))
gates = []
for gate in args[1:]:
  l, r = map(int, gate.split(' '))
  gates.append((l, r))
  
ids = range(1, n+1)
for gate in gates:
  l, r = gate
  ids = [x for x in ids if x in range(l, r+1)]
  
print(len(ids))


Fixed submission:
import sys
args = sys.stdin.readlines()
n, m = map(int, args[0].split(' '))
l_1 = 1
r_1 = n

for gate in args[1:]:
  l, r = map(int, gate.split(' '))  
  if l > l_1:
    l_1 = l
  if r < r_1:
    r_1 = r

ids = r_1 - l_1 + 1
if ids < 0:
  print(0)
else:
  print(ids)

Buggy python submission (verdict: Runtime Error):
import sys
args = sys.stdin.readlines()
n, m = map(int, args[0].split(' '))
gates = []
for gate in args[1:]:
  l, r = map(int, gate.split(' '))
  gates.append((l, r))
  
ids = gates[0]
for gate in gates[1:]:
  l, r = gate
  ids = [x for x in ids in range(l, r+1)]
  
print(len(ids))


Fixed submission:
import sys
args = sys.stdin.readlines()
n, m = map(int, args[0].split(' '))
l_1 = 1
r_1 = n

for gate in args[1:]:
  l, r = map(int, gate.split(' '))  
  if l > l_1:
    l_1 = l
  if r < r_1:
    r_1 = r

ids = r_1 - l_1 + 1
if ids < 0:
  print(0)
else:
  print(ids)

Buggy python submission (verdict: Runtime Error):
import sys
args = sys.stdin.readlines():
n, m = map(int, args[0].split(' '))
gates = []
for gate in args[1:]:
  l, r = map(int, gate.split(' '))
  gates.append((l, r))
  
ids = gates[0]
for gate in gates[1:]:
  l, r = gate
  ids = [x for x in ids in range(l, r+1)]
  
print(len(ids))

Fixed submission:
import sys
args = sys.stdin.readlines()
n, m = map(int, args[0].split(' '))
l_1 = 1
r_1 = n

for gate in args[1:]:
  l, r = map(int, gate.split(' '))  
  if l > l_1:
    l_1 = l
  if r < r_1:
    r_1 = r

ids = r_1 - l_1 + 1
if ids < 0:
  print(0)
else:
  print(ids)