import sys
input = sys.stdin.readline
sys.setrecursionlimit(500000)
N, K = map(int, input().split())

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

m = 998244353

S = []
for lr in LR:
    S.extend(range(lr[0], lr[1]+1))

from functools import lru_cache
@lru_cache(maxsize=None)
def getp(n):
    if n < 1:
        return 0
    elif n == 1:
        return 1
    else:
        return sum([getp(n-s) for s in S])%m

print (getp(N))