import numpy as np
N , K = map(int, input().split())

data = []
masu = np.zeros(N)
masu[0] = 1

for i in range(K):
  L, R = map(int,input().split())
  if L == R:
    data.append(L)
  else:
    for j in range(L,R+1):
      data.append(j)

for i in range(N):
  if masu[i] >= 1:
    for j in data:
      if i+j <= N-1:
        masu[i+j] += masu[i]
    if masu[N-1] >= 900000000:
      masu[N-1] = int(masu[N-1]) % 998244353

print(int(masu[N-1])%998244353)