n, k = [int(i) for i in input().split()]
a = []
for _ in range(k):
    x, y = [int(i) for i in input().split()]
    a.append([x, y])
a.sort()
dp = [0] * n
dp[0] = 1
for i in range(1, n):
    for j in a:
        for s in range(j[0], j[1] + 1):
            if i >= s:
                dp[i] += dp[i - s]

print(int(dp[n - 1]) % 998244353)
