N,K=map(int,input().split())
table=[i for i in range(N+1)]
arr=[]
for i in range(K):
    a,b=map(int,input().split())
    arr+=table[a:b+1]
arr=set(arr)

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


for i in range(N):
    for j in range(N):
        for k in arr:
            if dp[i][j]!=0 and j+k<=N-1:
                dp[i+1][j+k]+=dp[i][j]

ans=0
for i in range(N):
    ans+=dp[i][-1]

print(ans%998244353)