import sys
sys.setrecursionlimit(10**7)

def input(): return sys.stdin.readline()[:-1]
mod = 10**9 + 7
mod2 = 998244353
def readInt():return int(input())
def readIntList():return list(map(int,input().split()))
def readStringList():return list(input())
def readStringListWithSpace():return list(input().split())
def readString():return input()

from itertools import accumulate
 
def execute():
    n,k = readIntList()
    s = set()
    for _ in range(k):
        l,r = readIntList()
        s.add(l)
        s.add(r)
    s = list(s)
    dp = [0]*(n+1)
    for i in s :
        dp[i] = 1
    # dp[0] = 1
    for val in range(1,n+1):
        for coin in s:
            if val >= coin:
                dp[val] += dp[val-coin]
    print(dp[n-1]%mod2)

    


    
 
if __name__ == "__main__":
    execute()

