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-1):
  for k in range(len(R)):
    for l in range(R[k][0], R[k][1] + 1):
      if j + l <= N - 1:
        num[j+l] += num[j]
print(num[N-1] % mod)