N, K = map(int, input().split())
mod = 998244353
R = []
num = [0 for i in range(N)]
num[0] = 1
for i in range(K):
  R.append(list(map(int, input().split())))
for j in range(0, N):
  for k in range(len(R)):
    if j + R[k][0] < N:
      num[j + R[k][0]] += sum(num[:j+1])
    if j + R[k][1] + 1 < N:
      num[j + R[k][1] + 1] -= sum(num[:j+1])
  if j == 0:
    num[0] = 0
ans = sum(num) % mod
print(ans)