import numpy as np
N,K = [int(a) for a in input().split()]
dp = [0]*N
dp[0] = 1
k = [0]*N
for _ in range(K):
    L,R = [int(a) for a in input().split()]
    for i in range(L,R+1): k[i-1]=1
#print(dp,k)
f = 998244353
for i in range(1,N):
    dp[i] = np.dot(dp[:i],k[:i][::-1]) %f
    #print(dp,dp[:i],k[:i][::-1])
print(int(dp[-1]))