import sys
input = sys.stdin.readline
INF = 10**18
sys.setrecursionlimit(10**6)
import itertools as it
import collections as cl
from collections import deque
import math
from functools import reduce
from collections import defaultdict
MOD = 998244353


def li():
    return [int(x) for x in input().split()]

N, K = li()

s = set()
for _ in range(K):
    a, b = li()
    for i in range(a, b+1):
        s.add(i)

# dp[i]: マスiに到達する方法の個数
dp = [0] * (N+1)
dp[0] = 1
for i in range(N):
    for j in range(1,N-i):
        if j in s:
            dp[i+j] += dp[i]
            dp[i+j] %= MOD
print(dp[N-1])

