from collections import deque
MOD = 998244353

N, K = [int(a) for a in input().split()]
L = []
R = []
S = set()
for _ in range(K):
    l,r = [int(a) for a in input().split()]
    L.append(l)
    R.append(r)
    S = S | set(list(range(l, r+1)))
# print(S)

q = deque()
q.append(1)
ans = 0
while q:
    v = q.popleft()
    if v == N:
        ans = (ans%MOD + 1)%MOD
    else:
        for n in S:
            if n+v <= N:
                q.append(n+v)
print(ans)