from sys import stdin

input = stdin.readline
from functools import lru_cache

MOD = 998244353


def solve():
    N,K = map(int,input().split())
    step = [tuple(map(int,inp.split())) for inp in stdin.read().splitlines()]\


    @lru_cache(None)
    def dp(n):
        if n == 1:
            return 1
        res = 0
        for a,b in step:
            if n <= a:
                continue
            for i in range(a,b+1):
                if n > i:
                    res += dp(n-i)
        return res % MOD

    print(dp(N))


if __name__ == '__main__':
    solve()
