import sys

Z = 998244353


def input():
    return sys.stdin.readline().rstrip('\n')


def calc(N, K, LR):
    c = []
    for (l, r) in LR:
        for i in range(l, r + 1):
            c += [i]
    d = [0] * N
    d[0] = 1
    for i in range(N):
        if d[i] == 0:
            continue
        for e in c:
            if i + e < N:
                d[i + e] = (d[i + e] + d[i]) % Z
    return d[N - 1]


(N, K) = tuple([int(s) for s in input().split()])
LR = [tuple([int(s) for s in input().split()]) for _ in range(K)]
print(calc(N, K, LR))