import sys
sys.setrecursionlimit(10 ** 8)

mod = 998244353

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

step = []
for _ in range(K):
    L, R = map(int, sys.stdin.readline().strip().split())
    step.append((L, R))
step.sort()

dp = [False] * (N + 1)
dp[1] = 1


def solve(u):
    if u <= 0:
        return 0

    if dp[u] is not False:
        return dp[u]
    
    dp[u] = 0
    for L, R in step:
        for i in range(L, R + 1):
            dp[u] += solve(u - i)
    return dp[u]


solve(N)

print(dp[-1] % mod)
