import sys
sys.setrecursionlimit(300000)

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

S_tmp = {}
for _ in range(K):
    l, r = map(int, input().split())
    S_tmp.update({ l : r })
#S = []
S_ = []
for l, r in sorted(S_tmp.items(), key=lambda x:x[0]):
    #S.extend( list(range(l,r+1)) )
    S_.append((l,r))


import numpy as np

A = np.array([0 for _ in range(N+1)])

#from functools import lru_cache
#@lru_cache(maxsize=None)

A[1] = 1
for n in range(2,N+1):
    A[n] = sum([ A[max(n-r,1):n-l+1].sum() % L for (l,r) in S_ if l < n ]) % L

print(A[n] % L)

def compute(n):
    if n == 1:
        return 1
    a = 0
    for s in S:
        if s >= n:
            break
        if A[n-s] is None:
            A[n-s] = compute(n-s)
        a += A[n-s]
    return a % L

#print(compute(N) % L)
