#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]

M = 998244353
n,k = ip()
seg = [ip() for i in range(k)]
dp = [0]*(n+1)
pre = [0]*(n+1)

dp[1] = 1
pre[1] = 1
for i in range(2,n+1):
    for l,r in seg:
        a,b = max(i-r,1),i-l
        dp[i] += (pre[b] - pre[a-1])%M
    pre[i] += (pre[i-1]+dp[i])%M
print(dp[n]%M)
