import bisect 
N,K =map(int, input().split())
mod = 998244353

x=[]
for i in range(K):
    x.append(list(map(int, input().split())))

lr = []
def hanni(l,r):
    for i in range (l,r+1):
        lr.append(i)
    return lr

for j in range (K):
    hanni(x[j][0],x[j][1])

a = list(set(lr))


#ここまで入力処理
#ここからdp

def bubunwa(a,N):
  p=998244353
  n=len(a)
  dp=[[0 for i in range(N+1)] for j in range(n+1)]
  dp[0][0]=1

  for i in range(n):
    for j in range(N+1):
      if a[i]<=j:  
        dp[i+1][j]=dp[i][j-a[i]]+ dp[i][j]% p
      else: 
        dp[i+1][j]=dp[i][j]%p
  return dp[n][N]


print(bubunwa(a,N-1))