n, k = map(int, input().split())
lr = []
for _ in range(k):
    l, r = map(int, input().split())
    for i in range(l, r + 1):
        lr.append(i)
lr = set(lr)
lr = sorted(lr)
dp = [0] * (n + 1)
dp[n] = 1
for i in range(n, 1, -1):
    for step in lr:
        if step <= i:
            dp[i - step] += dp[i] % 998244353
            dp[i - step] %= 998244353
        else:
            break
print(dp[1])