Problem:


Score : 300 points

Problem Statement

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?

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq M \leq 10^5

1 \leq L_i \leq R_i \leq N

Input

Input is given from Standard Input in the following format:

N M
L_1 R_1
L_2 R_2
\vdots
L_M R_M

Output

Print the number of ID cards that allow us to pass all the gates alone.

Sample Input 1

4 2
1 3
2 4

Sample Output 1

2

Two ID cards allow us to pass all the gates alone, as follows:

The first ID card does not allow us to pass the second gate.

The second ID card allows us to pass all the gates.

The third ID card allows us to pass all the gates.

The fourth ID card does not allow us to pass the first gate.

Sample Input 2

10 3
3 6
5 7
6 9

Sample Output 2

1

Sample Input 3

100000 1
1 100000

Sample Output 3

100000



Sample input:
4 2
1 3
2 4


Sample output:
2

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n, m = map(int, input().split())

pass_id = [0 for i in range(n)]

for _ in range(m):
    l, r = map(int, input().split())
    for i in range(l - 1, r):
        pass_id[i] += 1

# print(pass_id)
print(pass_id.count(m))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
m = set(range(N))
for i in range(M):
	L, R = map(int, input().split())
	_m = set(range(L-1, R))
	m = m & _m
	if m == set() : break
print(len(m))

Submission status: Time Limit Exceeded

Solution code:
nm = list(map(int, input().split()))
n = nm[0]
m = nm[1]

gates = [list(map(lambda x: int(x), input().split())) for i in range(m)]

keys = [i+1 for i in range(n)]
key_count = [0 for i in range(n)]

for gate in gates:
  new_key = keys.copy()

  for key in keys:
    if (key >= gate[0] and key <= gate[1]):
      key_count[key-1] += 1
    else:
      new_key.remove(key)
  keys = new_key

print(len(keys))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n,m = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(m)]
n = np.array([0]*n)
for l,r in LR:
  n[l-1:r] += 1.
print(sum(n == m))

Submission status: Time Limit Exceeded

Solution code:
N,M =map(int,input().split())
L = [0]*M
R = [0]*M
ans = int(0)

for i in range(M):
    L[i],R[i] = list(map(int,input().split()))


for i in range(N):
    j = int(0)
    while (R[j]>=i+1>=L[j]) :
        j += 1
        if j==M:
            ans +=1
            break


print(ans)

Submission status: Time Limit Exceeded

Solution code:
(N, M) = (int(i) for i in input().split(' '))
cards = set(range(1,N+1))

for i in range(0,M):
    # gate i can be opened by following card set
    (l, r) = (int(j) for j in input().split(' '))
    #print(cards, set(range(l,r+1)))
    cards = cards.intersection(set(range(l,r+1)))

print(len(cards))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

n, m = map(int, input().split())

card = set(range(1, n+1))

card

gate = []
for i in range(m):
    l, r = map(int, input().split())
    card = card & set(range(l, r+1))

print(len(card))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
o = [1]*n
for i in range(m):
    l, r = map(int, input().split())
    for j in range(n):
        if not(l <= j+1 <= r) :
            o[j]=0
c=0         
for i in range(n):
    c += o[i]
print(c)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())

l, r = map(int, input().split())
gate = set(range(l, r+1))
for i in range(m-1):
    l, r = map(int, input().split())
    gate = set(range(l, r+1)) & gate

print(len(gate))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())

L = []
R = []
C = [1] * N

for i in range(M):
    a, b = map(int, input().split())
    L.append(a)
    R.append(b)

for i in range(M):
    a = L[i] - 1
    b = R[i]

    if a == 0:
        C[b:] = [0] * (len(C)-b)
    elif b-1 == len(C):
        C[:a] = [0] * a
    else:
        C[b:] = [0] * (len(C) - b)
        C[:a] = [0] * a

print(sum(C))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
C={i for i in range(1,N+1)}

for _ in range(M):
    LR=list(map(int,input().split()))
    C=C&{k for k in range(LR[0],LR[1]+1)}
print(len(C))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
LR = [list(map(int, input().split())) for i in range(M)]

seki = set(list(range(LR[0][0],LR[0][1]+1)))
for i in range(M):
    seki &= set(list(range(LR[i][0], LR[i][1]+1)))

print(len(seki))

Submission status: Time Limit Exceeded

Solution code:
L, R = [[], []]
N, M = map(int, input().split())
for i in range(M):
  l, r = map(int, input().split())
  L.append(l)
  R.append(r)

count = 0
for i in range(1,N+1):
  s = True
  for j in range(M):
    if L[j]>i or i>R[j]:
      s = False
      break
  if s:
    count = count + 1

print('%d' % count)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())

list = [1]*N

for i in range(M):
	L, R = map(int, input().split())
	list[:L-1] = [0]*len(list[:L-1])
	list[R:] = [0]*len(list[R:])

print(list.count(1))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

# -*- coding: utf-8 -*-
"""
Created on Sat Apr 13 09:53:12 2019

@author: Owner
"""
import numpy as np
import sys
import collections
import scipy.misc
import math
from operator import itemgetter
import itertools
import copy
import bisect

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)

    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]
    

"""
N, X = map(int, input().split())

x = list(map(int, input().split()))

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

# 多次元配列の宣言（あとでintにすること。）（タプルにすること。）
dp = np.zeros((N+1, 4,4,4))
    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break
# 累積和
add = 1 # 問題によって決まる
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)

#２分探索
li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    

#ソート関数
org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)
# [3, 1, 4, 5, 2]
# [1, 2, 3, 4, 5]

#Distance Transformation
    for h in range(0,H):
        for w in range(0,W):
            if h == 0 and w == 0:
                pass
            elif h == 0:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h-1][W-w]+1)
            elif w == 0:   
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1)
            else:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1, D[H-h-1][W-w]+1, D[H-h][W-w]+2)
            d_max = max(D[H-h-1][W-w-1], d_max)

"""



N, M = list(map(int, input().split()))
L=[0]*M
R=[0]*M

col = np.zeros(N+1)

for i in range(M):
    L[i], R[i] = map(int, input().split())
    col[L[i]:R[i]+1] = col[L[i]:R[i]+1] + 1


def main(): 
    res = collections.Counter(col)
    print(res[M])
                
                
                
            
            
                

    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
num = []
num = [int(i) for i in input().split()]

gate = []

for temp in range(num[1]):
    temp = []
    temp = [int(i) for i in input().split()]
    gate.append(temp)

check = [0] * num[0]

for temp in gate:
    for kazu in range(num[0]):
        if kazu + 1 < temp[0]:
            check[kazu] = 1
        elif kazu + 1 > temp[1]:
            check[kazu] = 1

print(check.count(0))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
L=[]
R=[]
Nlist = list(range(1,N+1))
for i in range(M):
  L_n,R_n = map(int,input().split())
  L.append(L_n)
  R.append(R_n)
for i in range(M):
  Nlist = [k for k in Nlist if (k > (L[i]-1)) and (k < (R[i]+1))]
print(len(Nlist))

Submission status: Time Limit Exceeded

Solution code:
import collections

n, m = map(int, input().split())
ans = []

def addNum(ans):
    a, b = map(int, input().split())
    for i in range(a, b+1):
        ans.append(i)

for i in range(m):
    addNum(ans)

res = collections.Counter(ans)

count = 0
for i in res.values():
    if i == m:
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int, input().split())
ans=[0]*n
for _ in range(m):
    l,r=map(int, input().split())
    for i in range(1, n+1):
        if l<=i<=r:
            ans[i-1]+=1
print(ans.count(m))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())

list = [0 for i in range(N + 1)]

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

count = 0
for i in range(len(list)):
    if list[i] == M:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split(" "))
ans = 0
GATE_ID = []
for i in range(M):
    GATE_ID1,GATE_ID2 = map(int,input().split(" "))
    GATE_ID.append([GATE_ID1,GATE_ID2])
#print(GATE_ID)

for i in range(N):
    CARD_ID = i+1
    #print("CARD_ID:",CARD_ID)
    ALL_GATE_PASS_COUNT = 0
    for j in range(M):
        GATE_ID1,GATE_ID2 = GATE_ID[j][0],GATE_ID[j][1]
        #print(GATE_ID1,GATE_ID2)
        if CARD_ID >= GATE_ID1 and CARD_ID <= GATE_ID2:
            ALL_GATE_PASS_COUNT += 1
            #print(CARD_ID,":PASS")
    #print("ALL_GATE_PASS_COUNT:",ALL_GATE_PASS_COUNT)
    if ALL_GATE_PASS_COUNT == M:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
L=[list(map(int,input().split())) for i in range(m)]
#print(L)
M=0
ans = set(list(range(L[M][0],L[M][1]+1)))
for M in range(m):
  a=set(list(range(L[M][0],L[M][1]+1)))
  ans = a&ans
  #print(ans)
print(len(list((ans))))

Submission status: Time Limit Exceeded

Solution code:
# n=int(input())  #数値入力 「N」だけの入力のとき
# a,b=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
# c=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
# s=[list(map(int,list(input()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a=100
# b=0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋めのときの出力
# 000100-0.987654

import numpy as np
import math
import copy

N,M=map(int, input().split())
A=set([i for i in range(N+1)[1::]])

for _ in range(M):
    L,R=map(int, input().split())
    tmp=set([i for i in range(R+1)[L::]])
    A = A & tmp

print(len(A))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
a=[]
for i in range(m):
    l,r=map(int,input().split())
    
    if(i==0):
        x=set(range(l,r+1))
    else:
        y=set(range(l,r+1))
        x=x.intersection(y)
print(len(x))

Submission status: Time Limit Exceeded

Solution code:
numCard, numGate = map(int, input().split())
idList = []
for i in range(numGate):
        L, R = map(int, input().split())
        idList.extend([i for i in range(L, R+1)])

rootCards = [i for i in set(idList) if idList.count(i) == numGate]
print(len(rootCards))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int,input().split())
li = [0]*N
for i in range(M):
    L, R = map(int,input().split())
    for j in range(L-1,R,1):
        li[j] += 1
print(li.count(M))

Submission status: Time Limit Exceeded

Solution code:
M,N = map(int,input().split())
L = [list(map(int,input().split())) for i in range(N)]
Z=list(range(1,M+1))
ans = set(Z)
for s in L:
  k = set(range(s[0], s[1]+1))
  ans = ans & k
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
lr=[[int(i) for i in input().split()] for i in range(m)]
cnt=[i for i in range(lr[0][0],lr[0][1]+1)]
ans=len(cnt)
for i in range(m):
    cnt=list(set([i for i in range(lr[i][0],lr[i][1]+1)])&set(cnt))
    ans=len(cnt)
    if len(cnt)==0:
        ans=0
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
N,M = map(int , sys.stdin.readline().split())
A=[map(int , input().split()) for _ in range(M)]
data = np.zeros(N)
for L,R in A:
	data[L-1:R] +=1
print(np.sum(data == M))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
ans = []
if m == 1:
    l, r = map(int, input().split())
    print(r-l+1)
else:
    for i in range(m):
        l, r = map(int, input().split())
        ans += [x for x in range(l, r+1)]

    ans = [x for x in set(ans) if ans.count(x) >= m]
    print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
L = []
R = []
total = 0
for i in range(0,M):
    l,r = map(int,input().split())
    L.append(l)
    R.append(r)
for i in range(1,N+1):
    for j in range(0,M):
        if L[j] <= i <= R[j]:
            if j == M-1:
                total += 1
        else:
            break

print(total)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
gate=[]
for i in range(m):
  l=list(map(int,input().split()))
  gate.append(l)
count=[0]*n
for g in range(m):
  for j in range(gate[g][0],gate[g][1]+1):
      count[j-1]+=1
ans=0
for i in range(n):
    if count[i]==m:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: UTF-8
# sample code

v = list(map(int, input().split()))
n, m = v[0], v[1]

l, r = [], []
for i in range(m):
	v = list(map(int, input().split()))
	l.append(v[0])
	r.append(v[1])

num = 0
for i in range(n):
	flag = 0
	for j in range(m):
		if not((l[j]<=i+1) and (i+1<=r[j])):
			flag += 1
	if flag == 0:
		num += 1

print(num)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())

list = [1]*N

for i in range(M):
	L, R = map(int, input().split())
	list[:L-1] = [0]*len(list[:L-1])
	list[R:] = [0]*len(list[R:])

print(list.count(1))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split(' '))
for i in range(m):
    l, r = map(int, input().split(' '))
    a = set(j for j in range(l, r+1))
    if i == 0:
        result = a
    else:
        result = result & a
print(len(list(result)))

Submission status: Time Limit Exceeded

Solution code:
def main():
    N, M = map(int, input().split())
    A = [0] * N
    for _ in range(M):
        L, R = map(int, input().split())
        for i in range(L - 1, R):
            A[i] += 1
    print(A.count(M))


main()

Submission status: Time Limit Exceeded

Solution code:
import sys

fin = sys.stdin.readline
N, M = [int(elem) for elem in fin().split()]
conditions = [tuple(int(elem) for elem in fin().split()) for _ in range(M)]

current_set = set(range(1, 100001))
for l, r in conditions:
    new_set = set(range(l, r+1))
    current_set = new_set & current_set

print(len(current_set))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(M)]
li = [i for i in range(1, N+1)]
ans = li
for lr in LR:
  ans = [i for i in ans if lr[0] <= i <= lr[1]]
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())

id_list = []
for i in range(1, N + 1):
    id_list.append(i)

for _ in range(M):
    L, R = map(int, input().split())
    tmp = []
    for i in range(L, R + 1):
        tmp.append(i)
    id_list = list(set(id_list) & set(tmp))

print(len(id_list))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n,m = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(m)]
n = np.zeros(n)
for l,r in LR:
  n[l-1:r] += 1
print(sum(n == m))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
gate=[]
for i in range(m):
    gate.append([int(i) for i in input().split()])
count=0
for k in range(1,n+1):
    g=0
    for j in gate:
        if j[0]<=k<=j[1]:
            g+=1
    if g==m:
        count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
cards = set(range(1, N+1))
for i in range(M):
    L, R = map(int, input().split())
    cards &= set(range(L, R+1))
print(len(cards))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())

gate = []

for i in range(M):
    l, r = map(int, input().split())
    tmp = []
    for j in range(l, r + 1):
        tmp.append(j)
    gate.append(tmp)

gate_sum = set(gate[0])

for i in gate:
    gate_sum = gate_sum & set(i)

print(len(gate_sum))

Submission status: Time Limit Exceeded

Solution code:
S = []
N, M = input().split(" ")
for m in range(int(M)):
  a, b = input().split(" ")
  S.append(set([i for i in range(int(a),int(b)+1)]))
if M == 1:
  print(len(S[0]))
else:
  sets = S[0]
  for i in range(1,int(M)):
    sets = sets & S[i]
  print(len(sets))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())

id = [0] * (N+1)

for i in range(M):
    L, R = map(int, input().split())
    for j in range(L, R+1):
        id[j] += 1

cnt = 0
for i in range(1, N+1):
    if id[i] == M:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
S = [list(map(int, input().split())) for i in range(M)]
ans = set(range(S[0][0], S[0][1] + 1))
for s in S[1:] :
    a = set(range(s[0], s[1] + 1))
    ans = ans & a
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

import math

n,m = list(map(int,input().split(" ")))

idl = []
idr = []

for i in range(m):
    a,b = list(map(int,input().split(" ")))
    idl.append(a)
    idr.append(b)

ans  = 0

for i in range(n):
    flg = 0
    for j in range(m):
        if idl[j] <= i+1 <= idr[j]:
            pass
        else:
            flg = 1
    if flg == 0:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M = list(map(int,input().split()))

LR = []

for i in range(M):
    LR.append(list(map(int,input().split())))

cnt = 0

for i in range(1,N+1):
    for lr in LR:
        if i < lr[0] or i > lr[1]:
            break
    else:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# IMPORT ###############################################################################################################
import sys                                                      # システム
sys.setrecursionlimit(10**6)                                    # 再帰処理の上限変更
from collections import deque, Counter                          # キュー・個数カウント
from itertools   import accumulate, permutations, combinations  # 累積和・順列・組み合わせ
from operator    import itemgetter                              # ソート補助
from bisect      import bisect_left, bisect_right, bisect       # 二分探索
from heapq       import heappop, heappush                       # プライオリティキュー
from fractions   import gcd                                     # 最大公約数
from math        import ceil, floor, sqrt, cos, sin, tan, pi    # 数学処理
from copy        import deepcopy                                # オブジェクトコピー
import numpy         as np                                      # 数値計算

# MAIN #################################################################################################################
def main():
    # Init #############################################################################################################
    im = InputManager()
    # Input ############################################################################################################
    n, m = im.inputMultiple()
    gates = [1 for _ in range(n)]
    for _ in range(m):
        l, r = im.inputMultiple()
        for i in range(0, l - 1):
            gates[i] = 0
        for i in range(r, n):
            gates[i] = 0
    # Logic ############################################################################################################

    # Output ###########################################################################################################
    print(gates.count(1))
    # Return ###########################################################################################################
    return

# INPUT MANAGER ########################################################################################################
class InputManager(object):
    def __init__(self):
        pass

    @staticmethod
    def inputSingle(dtype=int):
        return dtype(input())
    
    @staticmethod
    def inputMultiple(dtype=int, aslist=False):
        if aslist:
            return list(map(dtype, input().split()))
        else:
            return map(dtype, input().split())

    @staticmethod
    def input2D(h, dtype=int):
        return [list(map(dtype, input().split())) for i in range(h)]

# CALL MAIN ############################################################################################################
main()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
n, m = map(int, stdin.readline().split())
ans = set(range(1, n+1))
for i in range(m):
    l, r = map(int, stdin.readline().split())
    ans = ans & set(range(l, r+1))
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
N,M = [int(i) for i in input().split()]
L=[]
R=[]
for n in range(M):
    temp = [int(i) for i in input().split()]
    L.append(temp[0])
    R.append(temp[1])
init_set = set(range(L[0],R[0]+1))
for n in range(M-1):
    now_set = set(range(L[n+1],R[n+1]+1))
    init_set = (init_set & now_set)
print(len(init_set))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())

haba = list()
max_L = 0
min_R = 10 ** 5 + 1
for i in range(M):
    L, R = map(int, input().split())
    haba.append([L, R])
    max_L = max(max_L, L)
    min_R = min(min_R, R)

min_haba = set(range(max_L, min_R + 1))
ids = set()
for L, M in haba:
    h = set(range(L, R + 1))
    ids = ids.union(h.intersection(min_haba))

print(len(ids))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N, M = list(map(int, input().split()))
range_dict = Counter()
for _ in range(M):
    l, r = list(map(int, input().split()))
    for i in range(l, r+1):
        range_dict[i] += 1

print(len([v for k, v in range_dict.most_common() if v==M]))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())

L, R = map(int, input().split())
hoge = set(list(range(L, R+1)))

for i in range(1, M):
    L, R = map(int, input().split())
    hoge = hoge & set(list(range(L, R+1)))

print(len(hoge))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,M = map(int , input().split())
A=[map(int , input().split()) for _ in range(M)]
data = np.zeros(N)
for L,R in A:
	data[L-1:R] +=1
print(np.sum(data == M))

Submission status: Time Limit Exceeded

Solution code:
import os, sys, re, math

N, M = [int(s) for s in input().split(' ')]

cards = [True for _ in range(N+1)]
cards[0] = False

for _ in range(M):
    l,r = [int(s) for s in input().split(' ')]
    for i in range(1,l):
        cards[i] = False
    for j in range(r+1,len(cards)):
        cards[j] = False

print(sum(cards))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N,M = map(int, input().split())
idcard = np.ones(N)
label = np.arange(1,N+1)


for i in range(M):
    L,R = map(int, input().split())
    idcard[np.logical_or(label<L,R<label)] = 0

print(int(np.sum(idcard)))

Submission status: Time Limit Exceeded

Solution code:
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n,m =na()
ls = [i for i in range(1,n+1)]
for i in range(m):
    l, r = na()
    tmp = [j for j in range(l, r+1)]
    ls = list(set(ls) & set(tmp))

print(len(ls))

Submission status: Time Limit Exceeded

Solution code:
n,m = (int(x) for x in input().split())
l = [0]*m
r = [0]*m
hoge = [m]*n
for i in range(m):
    l[i],r[i] = (int(x) for x in input().split())
    
for i in range(m):
    for f in range(l[i]-1,r[i]):
        hoge[f] -= 1
count = 0
for j in hoge:
    if j == 0:
        count+= 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
li = input().split()
n = int(li[0])
m = int(li[1])
# IDカードn枚，　ゲートm個
l_r = []
# i番目のゲートはl~rのIDカードを持っていれば通過できる
l_r = [input().split() for i in range(m)]
answer = 0
for i in range(n):
    for lr in l_r:
        l = int(lr[0])
        r = int(lr[1])
        if l <= i + 1 and i + 1 <= r:
            continue
        else:
            break
    else:
        answer += 1
print(answer)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, M = map(int, input().split())



ables_list = np.zeros(N)

for i in range(M):
    L, R = map(int, input().split())
    L -= 1
    ables_list[L: R] += 1

count = 0
for i in range(N):
    if ables_list[i] == M:
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
nm = list(map(int, input().split()))
n = nm[0]
m = nm[1]

gates = [list(map(lambda x: int(x), input().split())) for i in range(m)]

key = [0 for i in range(n)]

for gate in gates:
  for i in range(len(key)):
    if (i+1 >= gate[0] and i+1 <= gate[1]):
      key[i] += 1

print(key.count(m))

Submission status: Time Limit Exceeded

Solution code:
import sys  
input = sys.stdin.readline

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


k = [0]*N
for i in range(M):
    l, r = list(map(int, input().split()))
    for q in range(l-1, r):
        k[q] += 1

ans = 0
for k_ in k:
    if k_ == M:
        ans +=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
input = sys.stdin.readline
 
# bisect_left(lists, 3)
# bisect_right(lists, 3)
 
def main():
	N, M = map(int, input().split(" "))
	#N = int(input())
	#S = input()

	LR = []
	min_i = -1
	max_i = -1
	for i in range(M):
		L, R = map(int, input().split(" "))
		LR.append((L, R))
		if i == 0:
			min_i = L
			max_i = R
		else:
			if L < min_i:
				min_i = L
			if max_i < R:
				max_i = R

	ans = 0
	for i in range(min_i, max_i+1):
		flg = True
		for j in LR:
			L, R = j

			if i <= R and i >= L:
				flg = True
			else:
				flg = False
				break
		if flg == True:
			#print("sss")
			ans += 1

	print(ans)


if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
n ,m = map(int, input().split())
L_R = []
for i in range(m):
    l, r = map(int, input().split())
    tmp = set()
    for i in range(l, r + 1):
        tmp.add(i)
    L_R.append(tmp)

result = L_R[0]
for target_set in L_R:
    result = result.intersection(target_set)

print(len(result))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
lis = [1]*(n+2)
lis[0] = 0
lis[-1] = 0

for k in range(m):
  i, j = map(int, input().split())
  lis[:i] = [0]*(i)
  lis[j+1:] = [0]*(n - j + 2)
  
print(sum(lis))

Submission status: Time Limit Exceeded

Solution code:
import sys

N, M = map(int, sys.stdin.readline().split())

L = []
R = []

for i in range(M):
    temp_l, temp_r = map(int, sys.stdin.readline().split())
    L.append(temp_l)
    R.append(temp_r)

master_list = list(range(1, N+1))
master_set = set(master_list)

ans = master_set
for i in range(M):
    current_set = set(list(range(L[i], R[i]+1)))
    ans = ans & current_set

print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, M = map(int, input().split())

list = [[0 for i in range(N + 1)] for j in range(M)]

for m in range(M):
    l, r = map(int, input().split())
    for i in range(l,r+1):
        list[m][i] = 1
#print(list)
list = np.array(list)
sum = list.sum(axis=0)
#print(sum)
count = 0
for i in range(len(sum)):
    if sum[i] == M:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())

K = set(range(1, N + 1))
for i in range(M):
    l, r = map(int, input().split())
    K = K & set(range(l, r + 1))

print(len(K))

Submission status: Time Limit Exceeded

Solution code:
N, M = list(map(int, input().split()))
gate = [True for i in range(N+1)]

for i in range(M):
    r, m = list(map(int, input().split()))
    gate[:r] = [False] * r
    gate[m+1:] = [False] * (N-m+1)

print(sum(gate))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
ans = []

for i in range(M):
    tmp = list(map(int, input().split()))
    if i == 0:
        ans = [x for x in range(tmp[0], tmp[1]+1)]
    else:
        cur = [x for x in range(tmp[0], tmp[1]+1)]
        ans = [x for x in cur if x in ans]

print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
N,M=(int(i) for i in input().split())
gate=[]
for i in range(M):
    gate.append([int(i) for i in input().split()])
    gate[i].append(gate[i][1]-gate[i][0])
gate=sorted(gate,key=lambda x:x[2])

answer=0
for i in range(N+1):
    ok=1
    for l,r,p in gate:
        if l<=i and i<=r:
            pass
        else:
            ok=0
            break
    if ok==1:
        answer+=1
print(answer)

Submission status: Time Limit Exceeded

Solution code:
n, m = input().split()
N = int(n)
M = int(m)


s = set([])
card = N
for i in range(M):
    l, r = input().split()
    L = int(l)
    R = int(r)

    for j in range(N):
        if L <= j+1 and j+1 <= R:
            pass
        else:
            s.add(j+1)

print(N - len(list(s)))