from functools import lru_cache


s = set()

def main():
    n, k = map(int, input().split())
    for i in range(k):
        l, r = map(int, input().split())
        for j in range(l, r + 1):
            s.add(j)

    # print(s)

    # for i in range(n):
    #     rec(i)


    print(rec(n - 1) % 998244353)



@lru_cache(maxsize=100000000)
def rec(x):
    if x == 0:
        return 1

    y = [rec(x - i) for i in s if x - i >= 0]
    return sum(y)

main()