n,k = map(int, input().split())
mod = 998244353
S = [tuple(map(int, input().split()))  for _ in range(min(n, k))]

dp = [0] * (n+1)
dp[1] = 1
for i in range(2, n+1):
    # もらうDP
    for l, r in S:
        ll = max(i-r, 0)
        rr = max(i-l+1, 0)
        dp[i] += sum(dp[ll: rr])
        dp[i] %= mod

print(dp[n])

