n, k = map(int, input().split())
allowed_jump = [False for i in range(n)]
for i in range(k):
    l, r = map(int, input().split())
    for i in range(r-l+1):
        allowed_jump[l+i] = True
allowed_jump2 = []
for i in range(n):
    if allowed_jump[i]:
        allowed_jump2.append(i)
ans = [0 for i in range(n)]
ans[0]=1
for i in range(n):
    for jump in allowed_jump2:
        if i-jump>= 0:
            ans[i] += ans[i-jump]
print(ans[n-1]%998244353)