import numpy as np

mod = 998244353

N, K = map(int, input().split())
LR = []
for _ in range(K):
    l, r = map(int, input().split())
    LR.append((l, r))

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

stop = False
while not stop:
    cnt = 0
    for i, (l, r) in enumerate(LR):
        l += cnt
        r += cnt
        if l > N:
            if i == 0:
                stop = True
            break
        else:
            dp[l:min(N+1, r+1)] += 1
    cnt += 1

print(dp[-1] % mod)
