import math

class SegmentTree():
    def __init__(self, size):
        self.size = 2**((size-1).bit_length())
        self.val = [0]*(self.size*2)
    
    def update(self, i, x):
        i += self.size
        self.val[i] = x
        
        while i > 0:
            i = i >> 1
            self.val[i] = self.val[2*i] + self.val[2*i+1]
    
    def rangeSum(self, l, r):
        l += self.size
        r += self.size

        l_sum = 0
        r_sum = 0

        while l < r:
            if l & 1:
                l_sum += self.val[l]
                l += 1
            l = l >> 1

            if r & 1:
                r -= 1
                r_sum += self.val[r]
            r = r >> 1

        return l_sum + r_sum
        
p = 998244353

N, K = map(int, input().split())

hop = []

for i in range(K):
    L, R = map(int, input().split())
    for j in range(L, R + 1):
        hop.append(j)

dp = SegmentTree(N)

dp.update(0,1)

for i in range(N - 1):
    for j in range(len(hop)):
        d_val = dp.rangeSum(i, i + 1) % p
        if i + hop[j] < N:
            d_val_n = dp.rangeSum(i + hop[j], i + hop[j] + 1) % p
            dp.update(i + hop[j], d_val_n + d_val)

print(dp.rangeSum(N - 1, N) % p)