import numpypy as np
N,K=map(int,input().split())
arr=np.array([0]*N)
for _ in range(K):
    l,r=map(int,input().split())
    arr[l-1:r]+=1
#print(arr)
dp=np.array([0]*(2*N))
dp[1]=1

for n in range(2,N+1):
    dp[n:n+N]+=(arr*(dp[n-1]%998244353))
    #print(dp)
print(dp[N]%998244353)