MOD = 998244353

N, K = map(int,input().split())
LR = [list(map(int,input().split())) for _ in range(K)]

# dp[i]: マスiに移動する方法
dp = [0] * 200010
dp[0] = 1

for i in range(N):
    for l, r in LR:
        if i+l < N:
            dp[i+l] += dp[i]
            dp[i+l] %= MOD
        if i+r < N:
            dp[i+r+1] -= dp[i]
            dp[i+r+1] %= MOD
    if i>=1:
        dp[i+1] += dp[i]
        dp[i+1] %= MOD

print(dp[N-1])
