#再帰の限度を拡張
import sys
sys.setrecursionlimit(1000000)

#再帰メモ化
from functools import lru_cache

MOD_BY = 998244353 

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

LR_list = list()

for i in range(K):
    L,R = map(int, input().split())
    LR_list.append((L,R))

@lru_cache(maxsize=1000)
def dp_search(now):
    if now == N:
        return 1
    elif now > N:
        return 0
    else:
        ans = 0
        for L,R in LR_list:
            for i in range(L,R+1):
                ans += dp_search(now+i)%MOD_BY
        
        return ans%MOD_BY

print(dp_search(1)%MOD_BY)