MOD = 998244353

n,k = map(int,input().split())
lr = [list(map(int,input().split())) for _ in range(k)]
dp = [0]*n
dp[0] = 1

newdp = 0

for i in range(1,n):
    for l,r in lr:
        if i-l>=0:
            newdp += dp[i-l]
            newdp %= MOD
        if i-r-1>=0:
            newdp -= dp[i-r-1]
            newdp %= MOD
        
        dp[i] = newdp

print(dp[-1])