mod = 998244353

def eratosthenes(n, start, l, r, array):
    # print(array, n, l, r)
    for i in range(l, r+1):
        if i+start > n:
            break
        array[i+start] = (array[start] + array[i+start]) % mod


def resolve():

    n, k = map(int, input().split())
    array = [0] * (n+1)
    array[1] = 1

    lr = []
    for i in range(k):
        l,r = map(int, input().split())
        lr.append((l,r))
    lr.sort(reverse=True)
    for start in range(1, n):
        for l,r in lr:
            eratosthenes(n, start, l, r, array)


    print(array[-1])
    # print(array)

if __name__ == "__main__":
    resolve()
