n, k = map(int, input().split())
l = []
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(1, n+1):
    for j in l:
        if i+j < n+1:
            dp[i+j] += dp[i]%998244353

print(dp[n]%998244353)