import numpy as np

N, K = map(int, input().split())

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

D = np.zeros(N, dtype=int)
D[0] = 1

for n in range(N):
  for lr in LR:
    for i in range(lr[0], lr[1] + 1): 	
    	D[n] += D[n - i] % 998244353
      
print(D[N - 1] % 998244353)
