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


m = 998244353

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

for i in range(n):
    for j in range(k):
        for a in range(l[j], r[j]+1):
            if i + a >= n:
                break
            dp[i+a] += dp[i]
            dp[i+a] %= m

print(dp[n-1])