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

# 合計がn-1になるように組み合わせる
dp = [0] * (n+1)
dp[1] = 1
for i in range(2, n+1):
    # もらうdp
    for si in S:
        if i > si:
            dp[i] += dp[i-si]
            dp[i] %= mod

print(dp[n])