Buggy python submission (verdict: Runtime Error):
import numpy as np

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

D = []

for _ in range(K):
    L, R = map(int, input().split())

    for i in range(L, R+1):
        D.append(i)

D.sort()

dp = np.zeros(300000)
dp[1] = 1

for d in D:
    for i in range(1, N//d)
        dp += np.roll(dp, i * d)
    dp %= 998244353

print(int(dp[N]))

Fixed submission:
N, K = map(int, input().split())

L, R = [], []

for _ in range(K):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

dp = [0] * 300000
dpsum = [0] * 300000
dp[1] = 1
dpsum[1] = 1

for i in range(2, N+1):
    for j in range(K):
        li = min(L[j], i)
        ri = min(R[j], i + 1)
        dp[i] += dpsum[i - li] - dpsum[i - ri - 1]

    dp[i] %= 998244353
    dpsum[i] = dpsum[i-1] + dp[i]

print(dp[N])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(110000)

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

D = []

for _ in range(K):
    L, R = map(int, input().split())

    for i in range(L, R+1):
        D.append(i)


dp_memo = [-1] * 300000
dp_memo[1] = 1

def dp(v):
    if dp_memo[v] != -1:
        return dp_memo[v]
    ret = 0
    for d in D:
        if v - d < 1:continue
        ret += dp(v - d)
    ret %= 998244353
    dp_memo[v] = ret
    return ret

print(dp(N))

Fixed submission:
N, K = map(int, input().split())

L, R = [], []

for _ in range(K):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

dp = [0] * 300000
dpsum = [0] * 300000
dp[1] = 1
dpsum[1] = 1

for i in range(2, N+1):
    for j in range(K):
        li = min(L[j], i)
        ri = min(R[j], i + 1)
        dp[i] += dpsum[i - li] - dpsum[i - ri - 1]

    dp[i] %= 998244353
    dpsum[i] = dpsum[i-1] + dp[i]

print(dp[N])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())

D = []

for _ in range(K):
    L, R = map(int, input().split())

    for i in range(L, R+1):
        D.append(i)

dp = [0] * 300000
dp[1] = 1

for i in range(2, N+1):
    for d in D:
        if i - d < 1:continue
        dp[i] += dp[i-d]
        dp[i] %= 998244353

print(dp[N])

Fixed submission:
N, K = map(int, input().split())

L, R = [], []

for _ in range(K):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

dp = [0] * 300000
dpsum = [0] * 300000
dp[1] = 1
dpsum[1] = 1

for i in range(2, N+1):
    for j in range(K):
        li = min(L[j], i)
        ri = min(R[j], i + 1)
        dp[i] += dpsum[i - li] - dpsum[i - ri - 1]

    dp[i] %= 998244353
    dpsum[i] = dpsum[i-1] + dp[i]

print(dp[N])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())

D = []

for _ in range(K):
    L, R = map(int, input().split())

    for i in range(L, R+1):
        D.append(i)

D.sort()

dp = [0] * 300000
dp[1] = 1

for i in range(2, N+1):
    for d in D:
        if i - d < 1:continue
        dp[i] += dp[i-d]
        dp[i] %= 998244353

print(dp[N])

Fixed submission:
N, K = map(int, input().split())

L, R = [], []

for _ in range(K):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

dp = [0] * 300000
dpsum = [0] * 300000
dp[1] = 1
dpsum[1] = 1

for i in range(2, N+1):
    for j in range(K):
        li = min(L[j], i)
        ri = min(R[j], i + 1)
        dp[i] += dpsum[i - li] - dpsum[i - ri - 1]

    dp[i] %= 998244353
    dpsum[i] = dpsum[i-1] + dp[i]

print(dp[N])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())

D = []

for _ in range(K):
    L, R = map(int, input().split())

    for i in range(L, R+1):
        D.append(i)

D.sort()

dp = [0] * 300000
dp[1] = 1

for i in range(2, N+1):
    for d in D:
        if i - d < 1:continue
        dp[i] += dp[i-d]
        dp[i] %= 998244353

print(dp[N])

Fixed submission:
N, K = map(int, input().split())

L, R = [], []

for _ in range(K):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

dp = [0] * 300000
dpsum = [0] * 300000
dp[1] = 1
dpsum[1] = 1

for i in range(2, N+1):
    for j in range(K):
        li = min(L[j], i)
        ri = min(R[j], i + 1)
        dp[i] += dpsum[i - li] - dpsum[i - ri - 1]

    dp[i] %= 998244353
    dpsum[i] = dpsum[i-1] + dp[i]

print(dp[N])