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