N, K = map(int, input().split())
L = []
R = []
for _ in range(K):
  l, r = map(int, input().split())
  L.append(l)
  R.append(r)
L.sort()
R.sort()
DP = [0] * N
DP[0] = 1

for i in range(N):
  for j in range(len(L)):
    for k in range(L[j], R[j] + 1):
      if i - k < 0:
        break
      if 0 <= i - k < N:
        DP[i] += DP[i - k]
print(DP[-1]%998244353)