import numpy as np  # noqa

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

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

jumps = np.array(jumps)
dp2 = np.zeros(K + 1)

dp = np.zeros(N + 1)
dp[1] = 1
for i in range(2, N + 1):
    for j, jump in enumerate(jumps):
        mn = max(0, i - jump[1])
        mx = max(mn, i - jump[0])
        if mn > 0:
            dp2[j] -= dp[mn - 1]
        if mx > 0:
            dp2[j] += dp[mx]
        dp[i] = (dp[i] + dp2[j]) % m


print(int(dp[N]))
