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

S = list()
for l,r in LR:
  S.extend(list(range(l, r+1)))
S = sorted(S)

path_num_dict = {1:1}
for i in range(2, N+1):
  path_num = 0
  for d in S:
    j = i - d
    if j >= 1:
      path_num += path_num_dict[j] % 998244353
    else:
      break
  path_num_dict[i] = path_num % 998244353
print(path_num_dict[N])