# import numpy as np
import sys, math, heapq
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
MOD = 998244353
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")

N, K = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(K)]
S = set()

for i in range(1, N + 1):
    for lr in LR:
        l, r = lr
        if i in range(l, r + 1):
            S.add(i)

dp = [0] * (N + 15)
dp[1] = 1
for i in range(1, N):
    for s in S:
        dp[i + s] += dp[i]
        dp[i + s] %= MOD
dp[N] %= MOD
print(dp[N])