import numpy as np

mod = 998244353

N, K = map(int, input().split())
LR = []
lmin = float('inf')

for _ in range(K):
    l, r = map(int, input().split())
    LR.append((l, r))
    lmin = min(l, lmin)

dp = np.array([0] * (N+1))
dp[1] += 1

for i in range(1, N+1, lmin):
    now = dp[i] % mod
    
    for l, r in LR:
        try:
            dp[i+l:i+r+1] += now
        except:
            break

print(dp[-1] % mod)
