import numpy as np
n, k = map(int, input().split())
sec = np.array([], dtype=np.int)
masu = np.zeros(n, dtype=np.int)
masu[0] = 1
for i in range(k):
    l, r = map(int, input().split())
    sec = np.hstack([sec, np.arange(l,r+1)])
sec.sort()

for i in range(n):
    until = np.where(i+sec > n)
    for step in sec[:until]:
        masu[i + step] += masu[i]
        masu[i + step] %= 998244353

print(masu[-1])