import sys
from functools import lru_cache
sys.setrecursionlimit(2000)


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

S = list()
for l,r in LR:
  S.extend(list(range(l, r+1)))
S = sorted(S)

@lru_cache(maxsize=1000)
def an(n):
    if n == 1:
        return 1
    elif n < 1:
        return 0
    return sum([an(n-d)%998244353 for d in S])%998244353

print(an(N))