Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(_) for _ in input().split()]
s = []
for i in range(k):
    l, r = [int(_) for _ in input().split()]
    for j in range(l, r+1):
        s.append(j)
# print(s)
dp = [0 for i in range(n)]
dp[0] = 1
# print(dp)
for i in range(n):
    for j in s:
        if i-j >= 0:
            dp[i] += dp[i-j]
    dp[i] = dp[i] % 998244353
    # print(dp)
print(dp[-1])

Fixed submission:
n, k = [int(_) for _ in input().split()]
s = []
for i in range(k):
    s.append([int(_) for _ in input().split()])
# print(s)
dp = [0 for i in range(n)]
dp[0] = 1
dp_s = [0 for i in range(n+1)]
dp_s[1] = 1
# print(dp)
# print(dp_s)
# print('*****************')
for i in range(1, n):
    for j in range(len(s)):
        r, l = s[j]
        if i-r >= 0:
            if i-l >= 0:
                dp[i] += dp_s[i-r+1] - dp_s[i-l]
            else:
                dp[i] += dp_s[i-r+1] - dp_s[0]
    dp[i] = dp[i] % 998244353
    # print(dp)
    dp_s[i+1] += dp_s[i] + dp[i]
    dp_s[i+1] = dp_s[i+1] % 998244353
    # print(dp_s)
    # print('*****************')
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(_) for _ in input().split()]
s = []
for i in range(k):
    s.append([int(_) for _ in input().split()])
# print(s)
dp = [0 for i in range(n)]
dp[0] = 1
dp_s = [0 for i in range(n+1)]
dp_s[1] = 1
# print(dp)
# print(dp_s)
# print('*****************')
for i in range(1, n):
    for j in range(len(s)):
        r, l = s[j]
        if i-r >= 0:
            if i-l >= 0:
                dp[i] += dp_s[i-r+1] - dp_s[i-l]
            else:
                dp[i] += dp_s[i-r+1] - dp_s[0]
    # print(dp)
    dp_s[i+1] += dp_s[i] + dp[i]
    # print(dp_s)
    # print('*****************')
print(dp[-1]%998244353)

Fixed submission:
n, k = [int(_) for _ in input().split()]
s = []
for i in range(k):
    s.append([int(_) for _ in input().split()])
# print(s)
dp = [0 for i in range(n)]
dp[0] = 1
dp_s = [0 for i in range(n+1)]
dp_s[1] = 1
# print(dp)
# print(dp_s)
# print('*****************')
for i in range(1, n):
    for j in range(len(s)):
        r, l = s[j]
        if i-r >= 0:
            if i-l >= 0:
                dp[i] += dp_s[i-r+1] - dp_s[i-l]
            else:
                dp[i] += dp_s[i-r+1] - dp_s[0]
    dp[i] = dp[i] % 998244353
    # print(dp)
    dp_s[i+1] += dp_s[i] + dp[i]
    dp_s[i+1] = dp_s[i+1] % 998244353
    # print(dp_s)
    # print('*****************')
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(_) for _ in input().split()]
s = []
for i in range(k):
    l, r = [int(_) for _ in input().split()]
    for j in range(l, r+1):
        s.append(j)
# print(s)
dp = [0 for i in range(n)]
dp[0] = 1
# print(dp)
for i in range(n):
    for j in s:
        if i-j >= 0:
            dp[i] += dp[i-j]
    # print(dp)
print(dp[-1]%998244353)

Fixed submission:
n, k = [int(_) for _ in input().split()]
s = []
for i in range(k):
    s.append([int(_) for _ in input().split()])
# print(s)
dp = [0 for i in range(n)]
dp[0] = 1
dp_s = [0 for i in range(n+1)]
dp_s[1] = 1
# print(dp)
# print(dp_s)
# print('*****************')
for i in range(1, n):
    for j in range(len(s)):
        r, l = s[j]
        if i-r >= 0:
            if i-l >= 0:
                dp[i] += dp_s[i-r+1] - dp_s[i-l]
            else:
                dp[i] += dp_s[i-r+1] - dp_s[0]
    dp[i] = dp[i] % 998244353
    # print(dp)
    dp_s[i+1] += dp_s[i] + dp[i]
    dp_s[i+1] = dp_s[i+1] % 998244353
    # print(dp_s)
    # print('*****************')
print(dp[-1])