from collections import deque
from typing import Collection

n,k = map(int,input().split())
lr = [tuple(map(int,input().split())) for i in range(k)]

s = list()
for li,ri in lr:
    s.extend(list(range(li,ri+1)))

"""dp = [0]*(n+10)
dp[0] = 1
q = deque([0])
while(q):
    print(dp)
    now = q.popleft()
    for si in s:
        if now+si < n:
            dp[now+si] += dp[now]
            q.append(now+si)
print(dp)
print(dp[n-1])
"""
mod = 998244353
ans = [0]*(n)
ans[0] = 1
for i in range(n):
    now = ans[i]
    if now:
        for si in s:
            if i+si < n:
                ans[i+si] += now
#print(ans)
print(ans[-1]%mod)
