N, K = map(int, input().split())
S = []

for i in range(K):
  s = list(map(int, input().split()))
  S.append(s)
  
DP = [0]*N
DP[0] = 1

#print(DP)

for i in range(1,N):
  T = 0
  for s in S:
    l = max(0,i-s[1])
    r = max(0,i-s[0]+1)
    T += sum(DP[l:r])
  DP[i] = T
  #print(DP)
  
print(DP[-1]%998244353)