import sys
sys.setrecursionlimit(100000000)

class Rec_memo:
    def __init__(self):
        self.memo = {}

    def solve(self,n,nums):
        # print(self.memo)
        nums_cleaned = [i for i in nums if i <= n]
        if n == 0 or nums_cleaned == []:
            return 0
        elif n == nums_cleaned[0]:
            return 1
        else:
            max_num = nums_cleaned[-1]
            if (n,max_num) in self.memo.keys():
                return self.memo[(n,max_num)]
            else:
                self.memo[(n,max_num)] = sum([self.solve(n-i,nums_cleaned) for i in nums_cleaned])
                return self.memo[(n,max_num)]

N,K = map(int,input().split())
nums = []
for _ in range(K):
    L,R = map(int,input().split())
    for i in range(L,R+1):
        nums.append(i)

nums.sort()
rec_memo = Rec_memo()
out = rec_memo.solve(N,nums)
print(out % 998244353)