N, K = map(int, input().split())
LR = [tuple(map(int, input().split())) for _ in range(K)]

mod = 998244353

result = [1]
for ni in range(1, N):
  result.append(0)
  for l, r in LR:
    for j in range(l, r+1):
      if ni-j<0: continue
      result[ni] = (result[ni]+result[ni-j]) % mod


print(result[N-1])
