import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplt(n): return [tuple(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n,k = inpm()
LR = inplt(k)

s = []
for l,r in LR:
    for i in range(l,r+1):
        s.append(i)
s.sort()
dp = [0.1] + [1] + [0]*(n-1)

# for i in range(2,n+1):
#     for j in s:
#         if i - j < 1:
#             break
#         dp[i] = (dp[i] + dp[i-j]) % 998244353

def f(x):
    if dp[x] != 0:
        return dp[x]
    else:
        ret = sum(map(f,[x-ss for ss in s if ss < x])) % 998244353
        dp[x] = ret
        return ret

print(f(n))