import sys
sys.setrecursionlimit(10000000)
input = sys.stdin.readline
n, k = map(int, input().split())
a = []
mod = 998244353
for i in range(k):
    l, r = map(int, input().split())
    for j in range(l, r + 1):
        a.append(j)
dp = [0] * (n + 20)
dp[0] = 1
for i in range(n):
    for j in a:
        dp[i + j] += dp[i]
        dp[i + j] %= mod

print(dp[n - 1])
