N, K = map(int, input().split())

DP = [0]*(N+1)
DP[1] = 1

S = set()
for i in range(K):
    l, r = map(int, input().split())
    for j in range(l, r+1):
      S.add(j)

S = sorted(list(S))

for i in range(1, N+1):
    for d in S:
        if i + d <= N:
            DP[i+d] += DP[i]%998244353

print(DP[N]%998244353)