n, k = map(int, input().split())
lr = []
for _ in range(k):
    l, r = map(int, input().split())
    lr.append([l,r])

masu = [0 for i in range(n)]
masu[0] = 1
len_lr = len(lr)

for i in range(1,n):
    for j in lr:
        if i - j[0] >= 0:
            for k in range(j[0],min(i+1, j[1])+1):
                masu[i] += masu[i-k]
                masu[i] %= 998244353


print(masu[-1])
