import sys
import numpy as np
import math  # gcdもあるよ
from collections import deque
from collections import defaultdict
from copy import deepcopy
from itertools import accumulate #リストを与えると累積和を返す
import bisect #二部探索
def input(): return sys.stdin.readline().rstrip()
from functools import lru_cache #メモ化
INF = 10**9 + 7
mod = 998244353

def main():
    n, k = list(map(int,input().split()))
    #data = [input().split() for _ in range(n)]
    #差集合Sをつくる
    S = []
    for _ in range(k):
        s = list(map(int,input().split()))
        #print(s)
        s_ = [i for i in range(s[0], s[1]+1)]
        #print(s_)
        S = list(set(S) | set(s_)) #和集合
    #print(S)

    square = [0 for _ in range(n+10)]
    square[0] = 1
    #print(square)
    for i in range(n):
        for j in S:
            if not i + j > n:
                square[i+j] += square[i]
                square[i+j] %= mod
            #print(square)
    print(square[n-1])
    return 0

if __name__ == "__main__":
    main()