n,k = map(int,input().split())
mod =  998244353
S = set([])
for i in range(k):
    L,R = map(int,input().split())
    for j in range(L,R+1):
        S.add(j)
S = list(S)
S = sorted(S)
dp = [0]*n
dp[0] = 1
for i in range(n):
    for x in S:
        if i+x < n:
            dp[i+x] += dp[i]
            dp[i+x] %= mod
print(dp[-1]%mod)