N,K=map(int,input().split())

arr=[]
for i in range(K):
    a,b=map(int,input().split())
    for j in range(a,b+1):
        if j not in arr:
            arr.append(j)

dp=[[0]*N for i in range(N)] 
dp[0][0]=1

ans=0
for i in range(N):
    for j in range(i,N):
        if dp[i][j]!=0:
            for k in arr:
                if j+k<=N-1:
                    dp[i+1][j+k]+=dp[i][j]
    ans+=dp[i][-1]
            
print(ans%998244353)