n,k = map(int,input().split())
S = []
mod = 998244353
for i in range(k):
    l,r = map(int,input().split())
    L = [x for x in range(l,r+1)]
    S = S + L
    #print(S)
    
dp = [0]*(n+1)
dp[0] = 1
for j in range(n):
    for i in S:
        #print(j,i)
        if j-i >=0:
            dp[j] += dp[j-i]
print(dp[n-1]%mod)