# coding:UTF-8
import sys
from math import factorial

MOD = 998244353
INF = 10000000000

def main():
    n, k = list(map(int, input().split()))  # スペース区切り連続数字
    lrList = [list(map(int, input().split())) for _ in range(k)]  # スペース区切り連続数字(行列)

    s = []
    for l, r in lrList:
        for i in range(l, r+1):
            s.append(i)

    Interm = [0] * (n + 1)
    Interm[0] = 0
    Interm[1] = 1
    for i in range(1, n+1):
        if i >= 2:
            for j in s:
                if n - j >= 1:
                    Interm[i] = (Interm[i] + Interm[i - j]) % 998244353

    result = Interm[n]
    # ------ 出力 ------#
    print("{}".format(result))

if __name__ == '__main__':
    main()
