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

jumps = []
for i in range(K):
    l, r = map(int, input().split())
    jumps.append([l, r])

dp = [0] * (N + 1)

dp[1] = 1
for i in range(2, N + 1):
    for j in jumps:
        mn = max(0, i - j[1])
        mx = max(mn, i - j[0])
        dp[i] = (dp[i] + sum(dp[mn:mx + 1])) % m
print(dp[N])
