N,K=map(int,input().split())
X=[list(map(int,input().split())) for i in range(K)]
C=[0]*(N*3)
DP=[0]*N
mod=998244353
DP[0]=1
Y=0
for i in range(N):
  Y+=C[i]
  DP[i]+=Y
  Y%=mod
  DP[i]%=mod
  for j in range(K):
    C[i+X[j][0]]+=DP[i]
    C[i+X[j][1]+1]-=DP[i]
print(DP[N-1])
