N, K = map(int, input().split())
L = []
for _ in range(K):
  a, b = map(int, input().split())
  L.append((a,b))
L.sort()
DP = [0]*N
DP[0]=1
for i in range(1, N):
  for l in L:
    for j in range(l[0], l[1]+1):
      if i>=j: 
        DP[i] += DP[i-j]
        DP[i] %= 998244353
      else:
        break
    else:
      continue
    break
print(DP[-1])