#D
N,K=map(int,input().split())
p=998244353
L=[0]*K
R=[0]*K
C=[0]*K
mov=set()
for i in range(K):
    L[i],R[i] = map(int,input().split())
    for i in range(L[i],R[i]+1):
        mov.add(i)
    #C[i] = [L[i],R[i]]
#C.sort()

dp = [0]*(N+1)
dp[1]=1
for i in range(2,N+1):
    for m in mov:
        if i-m>=1:
            dp[i] += dp[i-m]
            dp[i] %= p
    #print(dp[i])
print(dp[-1])