import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n, k = map(int, input().split())

p = 998244353

jump = []
for i in range(k):
    a, b = map(int, input().split())
    jump += list(range(a, b+1))

dp = [0]*(n+1+max(jump))
dp[0] = 1
for i in range(n):
    for j in range(len(jump)):
        dp[i+jump[j]] += dp[i]%p
        dp[i+jump[j]] %= p

print(dp[n-1]%p)