n, k = map(int, input().split())
lr = [list(map(int, input().split())) for _ in range(k)]

mod = 998244353
dp = [0]*n
dp[0] = 1
s = 0
for i in range(1, n):
    for j in range(k):
        if i-lr[j][0] < 0:
            continue
        elif i-lr[j][1] <= 0:
            s = (s + dp[i-lr[j][0]]) % mod
        elif 0 < i-lr[j][1]:
            s = (s + dp[i-lr[j][0]] - dp[i-lr[j][1]-1]) % mod
    dp[i] = s
print(dp[-1])