MOD = 998244353
inpl = lambda: tuple(map(int,input().split()))
N, K = inpl()
LR = [inpl() for _ in range(K)]
dp = [0]*N

c = 1
for i in range(N):
    c = (c + dp[i]) % MOD
    for L, R in LR:
        if i + L < N:
            dp[i+L] = (dp[i+L] + c) % MOD
            if i + R + 1 < N:
                dp[i+R+1] = (dp[i+R+1] - c) % MOD
print(dp[-1])
