import sys

input = sys.stdin.readline


def main():
    N, K = map(int, input().split())
    numbers = []
    for _ in range(K):
        L, R = map(int, input().split())
        for i in range(L, R + 1):
            numbers.append(i)
    numbers.sort()
    dp = [0] * N
    dp[0] = 1
    p = 998244353
    for i in range(N):
        for j in numbers:
            if i + j < N:
                dp[i + j] = (dp[i+j] + dp[i]) % p
            else:
                break
    print(dp[N-1])


if __name__ == '__main__':
    main()
