n, k = map(int, input().split())
mod = 998244353
list_s = []
for _ in range(k):
    l, r = map(int, input().split())
    list_s.extend(range(l, r + 1))

dp = [0] * (n+1)
sdp = [0] * (n+1)
dp[1] = 1
for i in range(2,n+1):
    for s in list_s:
        if s < i:
            dp[i] += dp[i-s]
print(dp[n] % mod)