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

LR = [map(int, input().split()) for _ in range(K)]
L, R = [list(i) for i in zip(*LR)]

dp = [0]*N
a=[0]*K
dp[0] = 1
for i in range(1, N):
  for j in range(K):
    if L[j] <= i < R[j]:
      a[j]+=dp[i-L[j]]
      dp[i]+= a[j]
    elif R[j] <= i:
      a[j]+=dp[i-L[j]]-dp[i-R[j]-1]
      dp[i]+=a[j]
      
print(dp[N-1] % mod)