import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,k = na()
mod = 998244353
dp = [1] + [0]*(n-1)
hw = []

for i in range(k):
    l,r = na()
    for j in range(l,r+1):
        hw.append(j)

hw.sort()
for i in range(n):
    for p in hw:
        if i-p >= 0:
            dp[i] = (dp[i]+dp[i-p])%mod

print(dp[-1])