MOD = 998244353

class BIT:
    def __init__(self, n, init=None):
        self.size = n
        if init is None:
            self.v = [0] * (n + 1) # don't use bit[0]
        else:
            self.v = [0] + init
            for i in range(1, n):
                if i + (i & -i) <= n: self.v[i + (i & -i)] += self.v[i]

    def sum(self, i):
        '''
        Calculate a[1] + ... + a[i]
        '''
        S = 0
        while i > 0:
            S += self.v[i]
            i -= i & -i
        return S

    def add(self, i, x):
        '''
        set a[i] to be a[i] + x
        '''
        assert i > 0
        while i <= self.size:
            self.v[i] += x
            i += i & -i

N, K = map(int, input().split())
segments = [tuple(map(int, input().split())) for _ in range(K)]
bit = BIT(N + 1)
bit.v[1] = 1
for i in range(1, N + 1):
    temp = bit.sum(i)
    for s, t in segments:
        if i + s <= N:
            bit.add(i + s, temp)
            bit.add(min(i + t + 1, N + 1), -temp)
print(bit.sum(N) % MOD)