Buggy python submission (verdict: Time Limit Exceeded):
mod = 998244353
N,K = map(int,input().split())
move = [list(map(int,input().split())) for _ in range(K)]

dp = [0]*(N+1)
dp_sum = [0]*(N+1)
dp[1] = dp_sum[1] = 1
for i in range(2,N+1):
    for l,r in move:
        if 0<i-l:
            dp[i] += dp_sum[i-l]
            if 0<i-r-1:
                dp[i] -= dp_sum[i-r-1]
    dp_sum[i] = dp_sum[i-1] + dp[i]
            
print(dp[-1]%mod)

Fixed submission:
mod = 998244353
N,K = map(int,input().split())
move = [list(map(int,input().split())) for _ in range(K)]

dp = [0]*(N+1)
dp_sum = [0]*(N+1)
dp[1] = dp_sum[1] = 1
for i in range(2,N+1):
    for l,r in move:
        if 0<i-l:
            dp[i] += dp_sum[i-l]
            if 0<i-r-1:
                dp[i] -= dp_sum[i-r-1]
        dp[i] %= mod
    dp_sum[i] = dp_sum[i-1] + dp[i]
            
print(dp[-1]%mod)

Buggy python submission (verdict: Time Limit Exceeded):
mod = 998244353
N,K = map(int,input().split())
move = []
for _ in range(K):
    x,y = map(int,input().split())
    for i in range(x,y+1):
        move.append(i)
move.sort()
move = set(move)
memo = [0]*(N+1)
memo[1] = 1
for i in range(1,N):
    if 0<memo[i]:
        for j in move:
            if i+j<=N:
                memo[i+j] += memo[i]
            else:
                break
        
print(memo[-1]%mod)

Fixed submission:
mod = 998244353
N,K = map(int,input().split())
move = [list(map(int,input().split())) for _ in range(K)]

dp = [0]*(N+1)
dp_sum = [0]*(N+1)
dp[1] = dp_sum[1] = 1
for i in range(2,N+1):
    for l,r in move:
        if 0<i-l:
            dp[i] += dp_sum[i-l]
            if 0<i-r-1:
                dp[i] -= dp_sum[i-r-1]
        dp[i] %= mod
    dp_sum[i] = dp_sum[i-1] + dp[i]
            
print(dp[-1]%mod)

Buggy python submission (verdict: Time Limit Exceeded):
mod = 998244353
N,K = map(int,input().split())
move = []
for _ in range(K):
    x,y = map(int,input().split())
    for i in range(x,y+1):
        move.append(i)
move.sort()
move = set(move)
memo = [0]*(N+1)
memo[1] = 1
for i in range(2,N+1):
    for j in move:
        if 0<i-j:
            memo[i] += memo[i-j]
        else:
            break
    memo[i] = memo[i]%mod
print(memo[-1]%mod)

Fixed submission:
mod = 998244353
N,K = map(int,input().split())
move = [list(map(int,input().split())) for _ in range(K)]

dp = [0]*(N+1)
dp_sum = [0]*(N+1)
dp[1] = dp_sum[1] = 1
for i in range(2,N+1):
    for l,r in move:
        if 0<i-l:
            dp[i] += dp_sum[i-l]
            if 0<i-r-1:
                dp[i] -= dp_sum[i-r-1]
        dp[i] %= mod
    dp_sum[i] = dp_sum[i-1] + dp[i]
            
print(dp[-1]%mod)

Buggy python submission (verdict: Time Limit Exceeded):
mod = 998244353
N,K = map(int,input().split())
move = set()
for _ in range(K):
    x,y = map(int,input().split())
    for i in range(x,y+1):
        move.add(i)

memo = [0]*(N+1)
memo[1] = 1
for i in range(2,N+1):
    for j in move:
        if 0<i-j:
            memo[i] += memo[i-j]
    memo[i] = memo[i]%mod
print(memo[-1]%mod)

Fixed submission:
mod = 998244353
N,K = map(int,input().split())
move = [list(map(int,input().split())) for _ in range(K)]

dp = [0]*(N+1)
dp_sum = [0]*(N+1)
dp[1] = dp_sum[1] = 1
for i in range(2,N+1):
    for l,r in move:
        if 0<i-l:
            dp[i] += dp_sum[i-l]
            if 0<i-r-1:
                dp[i] -= dp_sum[i-r-1]
        dp[i] %= mod
    dp_sum[i] = dp_sum[i-1] + dp[i]
            
print(dp[-1]%mod)