N,K=map(int,input().split())
L=list()
R=list()
dice=list()
dp=[0]*N
dp[0]=1
for i in range(K):
    l,r=map(int,input().split())
    for i in range(l,r+1):
        if i<=N-1:
            dice.append(i)
dice.sort()
for i in range(1,N):
    for j in range(len(dice)):
        if i-dice[j]<0:
            break
        else:
            dp[i]+=dp[i-dice[j]]%998244353
print(dp[N-1]%998244353)