N ,K = map(int,input().split())
S = []
mod = 998244353
for _ in range(K): 
    l,r = map(int,input().split())
    S += list(range(l,r+1))
dp = [0]*(N+10) 
dp[0]=1
for n in range(N):
    for i in S:
        if n >= i:
            dp[n] += dp[n-i]
print(dp[N-1]%mod)


