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

lr.sort()

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

for i in range(1,n):
    ok = 0
    ng = len_lr
    while ng-ok > 1:
        if i-lr[(ok+ng)//2] >=0:
            ok = (ok+ng)//2
        else:
            ng = (ok+ng)//2

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

print(masu[-1])
