# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# from time import time
# from itertools import product,permutations,\
    # combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

# mod = int(1e9+7)
mod = 998244353
INF = 1<<50

def readInt():
    return list(map(int,input().split()))

def main():
    n,k = readInt()
    s = set()
    for i in range(k):
        l,r = readInt()
        for j in range(l,r+1):
            s.add(j)
    s = list(s)
    s.sort()
    dp = [0 for i in range(n)]
    dp[0] = 1
    for i in range(n):
        if dp[i]==-1:
            continue
        for j in range(len(s)):
            if i+s[j]>=n:
                break
            dp[i+s[j]] += dp[i]
            dp[i+s[j]] %= mod
    print(dp[n-1])
    return

if __name__=='__main__':
    main()
