n, k = map(int, input().split())
value = []
for _ in range(k):
    l, r = map(int, input().split())
    tmp = [i for i in range(l, r + 1)]
    value += tmp
value.sort()
mod = 998244353
dp = [0 for _ in range(n)]
dp[0] = 1
for i in range(n - 1):
    for dist in value:
        if i + dist <= n - 1:
            dp[i + dist] = (dp[i] + dp[i + dist]) % mod
print(dp[-1])