import sys
input = sys.stdin.readline
N, K = map(int, input().split())

LR = [list(map(int, input().split())) for _ in range(K)]

m = 998244353

S = []
for lr in LR:
    S.extend(range(lr[0], lr[1]+1))

p = ['a']*N
p[0] = 1

def getpi(i):
    if i<0:
        return 0
    if p[i] == 'a':
        t = 0
        for s in S:
            t += getpi(i-s)
        t = t%m
        p[i] = t
        return t 
    else:
        return p[i]

print (getpi(N-1))