n, k = map(int, input().split())
lr = [map(int, input().split()) for i in range(k)]
l, r = zip(*lr)


m = 998244353


d = []
for i in range(k):
    for j in range(l[i],r[i]+1):
        d.append(j)

dp = [0 for i in range(n)]
dp[0] = 1

for i in range(n):
    for a in d:
        if i + a >= n:
            continue
        dp[i+a] += dp[i]
        dp[i+a] %= m

print(dp[n-1])