n, k = map(int, input().split())
s = set()
for i in range(k):
    a, b = map(int, input().split())
    l += [i for i in range(a, b+1)]

l = list(set(l))
dp = [0]*(n+1)
dp[1] = 1

for i in range(2, n+1):
    for j in l:
        cnt = 0
        sa = i-j
        if sa > 0:
            cnt += dp[i-j]
        dp[i] += cnt%998244353

print(dp[n]%998244353)