import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
N,K = map(int,input().split())
LR = [tuple(map(int,input().split())) for i in range(K)]
LR.sort()
MOD = 998244353

arr = []
for l,r in LR:
    for i in range(l,r+1):
        arr.append(i)

from functools import lru_cache
@lru_cache(maxsize=10**8)
def rec(n):
    if n==0: return 1
    ret = 0
    for a in arr:
        if n-a < 0: break
        ret += rec(n-a)
        ret %= MOD
    return ret

print(rec(N-1))