# -*- coding: utf-8 -*-
# 標準入力を取得
N, K = list(map(int, input().split()))
L, R = [], []
for k in range(K):
    L_k, R_k = list(map(int, input().split()))
    L.append(L_k)
    R.append(R_k)

# 求解処理
S = []
for k in range(K):
    for s in range(L[k], R[k] + 1):
        S.append(s)
S = sorted(S)

m = {i: 0 if i != 1 else 1 for i in range(1, N + 1)}
for i in range(1, N):
    for s in S:
        if i + s <= N:
            m[i + s] += m[i]
        else:
            break

ans = m[N] % 998244353

# 結果出力
print(ans)
