import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
M = 998244353


def main():
    N, K = map(int, readline().split())
    LR = list(list(map(int, readline().split())) for _ in range(K))
    LR.sort()
    dp = [0] *(N+1)
    dp[1] = 1
    for i in range(1, N + 1):
        for l,r in LR:
            for s in range(l,r+1):
                if i - s > 0:
                    dp[i] += dp[i - s]
                    dp[i] %= M
                else:
                    break
    print(dp[N])


if __name__ == '__main__':
    main()
