from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math
import threading
import sys
import time


def get_int(): return int(stdin.readline().strip())


def get_tuple(): return map(int, stdin.readline().split())


def get_list(): return list(map(int, stdin.readline().split()))

mod = 998244353
n,k = get_tuple()
st = list()
for _ in range(k):
    x,y = get_tuple()
    st.append([x,y])

dp = [1]
pref_sum = 1
last_val = 0
for i in range(1,n):
    curr_sum = 0
    for x,y in st:
        if i-x>=0:
            curr_sum += dp[i-x]
        if i - y >= 1:
                curr_sum -= dp[i - y - 1]
    pref_sum += curr_sum
    last_val = curr_sum
    dp.append(pref_sum)
diff = (dp[-1]-dp[-2])
if diff>0:
    print(diff%mod)
else: print(0)
# print(pref_sum)
# print(st,dp)
# print(dp[n-2]%mod)