mod = 998244353
N, K = map(int,input().split())
S = []
for _ in range(K):
    S.append(list(map(int,input().split())))
L = [1]
SUM = [1]
for i in range(1, N):
    tmp = 0
    for j in range(K):
        if i - S[j][0] >= 0:
            tmp += SUM[i - S[j][0]]
        if i - S[j][1] - 1 >= 0:
            tmp -= SUM[i - S[j][1] - 1]
    L.append(tmp % mod)
    SUM.append((L[-1] + SUM[-1]) % mod)

print(L[-1])