N,K = map(int, input().split())
S = [[int(s) for s in input().split()] for _ in range(K)]
mod = 998244353

dp = [0]*N
dp[0] = 1
if N > 2:
    dp[1] = -1
for i in range(N):
    if N > 2:
        dp[i] += dp[i-1]
    dp[i] %= mod
    for s in S:
        if s[0]+i < N:
            dp[s[0]+i] += dp[i]
            dp[s[0]+i] %= mod
        if s[1]+i+1 < N:
            dp[s[1]+i+1] -= dp[i]
            dp[s[1]+i+1] %= mod
print(dp[-1])