MOD = 998244353
N, K = map(int, input().split())
table = [False] * N
path = [0] * N

for i in range(K):
  l, r = map(int, input().split())
  for j in range(l-1, r):
    table[j] = True

path[0] = 1
for i in range(1, N):
  total = 0
  for j in range(i):
    if table[i-j-1]:
      total = (total + path[j]) % MOD
  path[i] = total

print(path[N-1])