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 = dict()
dp[0] = 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+pref_sum)%mod
    dp[i]=pref_sum
diff = (dp[n-1]-dp[n-2])
if diff>0:
    print(diff%mod)
else: print(0)