import sys
input = sys.stdin.readline

n, k = map(int,input().split())
lr = []
for _ in range(k):
    l, r = map(int,input().split())
    lr.extend([i for i in range(l, r+1)])

mod = 998244353
dp = [0]*(n+1)
dp[1] = 1

for i in range(1, n):
    for j in [k for k in lr if k <= n - i]:
        dp[i + j] += dp[i]

print(dp[n] % mod)