MOD = 998244353

N, K = map(int, input().split())
seg = [tuple(map(int, input().split())) for _ in range(K)]
dp = [0] * (N+1)
dp[0] = 1
for i in range(N):
    for s, t in seg:
        dp[i+s] += dp[i]
        dp[i+t;1] -= dp[i]
    dp[i+1] += dp[i]
    dp[i+1] %= MOD
    
print(dp[N-1])
