MOD = 998244353
N,K = map(int,input().split())
ran = []
DP = [0]*(N+1)
DP[1] = 1
for i in range(K):
  a,b = map(int,input().split())
  ran.extend([x for x in range(a,b+1)])
ran.sort()
for i in range(N+1):
  for j in ran:
    if j >= i:
      break
    DP[i] = (DP[i] + DP[i-j]) % MOD
print(DP[N])
