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(i):
        d = i - j
        for a in range(k):
            if d >= l[a] and d <= r[a]:
                dp[i] = (dp[i] + dp[j]) % m
                break

print(dp[n-1])