import sys
import itertools


def resolve(in_):
    N, K = map(int, next(in_).split())
    LR = tuple(tuple(map(int, line.split()) for line in itertools.islice(in_, K)))

    r = list(itertools.chain.from_iterable(iter(range(l, r + 1)) for l, r in LR))
    r.sort()
    dp = [0] * (N + 1)
    dp[1] = 1
    mod = 998244353

    for i in range(1, N + 1):
        for j in r:
            index = i - j
            if index > 0:
                dp[i] += dp[index]
                dp[i] %= mod
            else:
                break
    
    return dp[N]


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)

if __name__ == '__main__':
    main()

