Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
LR = set()
MOD = 998244353
import sys
sys.setrecursionlimit(10**6)

for i in range(K):
    l, r = map(int, input().split())
    for j in range(l, r + 1):
        LR.add(j)
#print(list(LR))


class Search:
    def __init__(self):
        self.ans = 0

    def dfs(self, now):
        if now == N:
            self.ans += 1
            return
        if now > N:
            return
        for d in LR:
            self.dfs(d + now)


s = Search()
s.dfs(1)
print(s.ans % MOD)

# LR = [list(map(int,input().split())) for i in range(N)]
# dp = [0] * (N + 1)
# dp[0] = 1
# for i in range(1, N):
#     for d in LR:
#         if i - d < 0: break
#         dp[i] += (dp[i - d]) % MOD
# print(dp[N-1] % MOD)


Fixed submission:
N, K = map(int, input().split())
LR = [list(map(int, input().split())) for i in range(K)]
MOD = 998244353

dp = [0] * (N + 1)
dp[1] = 1
dp_sum = [0] * (N + 1)
dp_sum[1] = 1


def get(l, r, i):
    return dp_sum[max((i - l), 0)] - dp_sum[max((i - r-1), 0)]


for i in range(1, N+1):
    for l, r in LR:
        dp[i] += get(l, r, i) % MOD
    dp_sum[i] = (dp_sum[i - 1] + dp[i])%MOD
print(dp[N] % MOD)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
LR = set()
MOD = 998244353

for i in range(K):
    l, r = map(int, input().split())
    for j in range(l, r + 1):
        LR.add(j)
#print(list(LR))


class Search:
    def __init__(self):
        self.ans = 0

    def dfs(self, now):
        if now == N:
            self.ans += 1
            return
        if now > N:
            return
        for d in LR:
            self.dfs(d + now)


s = Search()
s.dfs(1)
print(s.ans % MOD)

# LR = [list(map(int,input().split())) for i in range(N)]
# dp = [0] * (N + 1)
# dp[0] = 1
# for i in range(1, N):
#     for d in LR:
#         if i - d < 0: break
#         dp[i] += (dp[i - d]) % MOD
# print(dp[N-1] % MOD)


Fixed submission:
N, K = map(int, input().split())
LR = [list(map(int, input().split())) for i in range(K)]
MOD = 998244353

dp = [0] * (N + 1)
dp[1] = 1
dp_sum = [0] * (N + 1)
dp_sum[1] = 1


def get(l, r, i):
    return dp_sum[max((i - l), 0)] - dp_sum[max((i - r-1), 0)]


for i in range(1, N+1):
    for l, r in LR:
        dp[i] += get(l, r, i) % MOD
    dp_sum[i] = (dp_sum[i - 1] + dp[i])%MOD
print(dp[N] % MOD)

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

for i in range(K):
    l, r = map(int, input().split())
    for j in range(l, r + 1):
        LR.add(j)
#print(list(LR))

# LR = [list(map(int,input().split())) for i in range(N)]
dp = [0] * (N + 1)
dp[0] = 1
for i in range(1, N):
    for d in LR:
        if i - d < 0: break
        dp[i] += (dp[i - d]) % MOD
print(dp[N-1] % MOD)


Fixed submission:
N, K = map(int, input().split())
LR = [list(map(int, input().split())) for i in range(K)]
MOD = 998244353

dp = [0] * (N + 1)
dp[1] = 1
dp_sum = [0] * (N + 1)
dp_sum[1] = 1


def get(l, r, i):
    return dp_sum[max((i - l), 0)] - dp_sum[max((i - r-1), 0)]


for i in range(1, N+1):
    for l, r in LR:
        dp[i] += get(l, r, i) % MOD
    dp_sum[i] = (dp_sum[i - 1] + dp[i])%MOD
print(dp[N] % MOD)