N,K = map(int,input().split())
lis = [list(map(int,input().split())) for _ in range(K)]
 
T = []
 
for i in range(K):
    for j in range(lis[i][0],lis[i][1]+1):
        T.append(j)
        if i==0:
            S = set(T)
        else:
            S = S | set(T)
    T = []
 
lis = list(S)
dp  = [0]*(N+1)
dp[1] = 1
MOD = 998244353
 
for i in range(2,N+1):
    for j in lis:
        if i>j:
            dp[i] += dp[i-j]

print(dp[N]%MOD)