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)))
s.sort()
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%mod
                ans[i+si] %= mod
            else:
                break
#print(ans)
print(ans[-1]%mod)
