
dp = []
syugo = set()

def main():
    global syugo
    global dp
    n, k = map(int, input().split())

    for i in range(k):
        s, e = map(int, input().split())
        for j in range(s, e+1):
            syugo.add(j)

    dp = [0]*n

    for i in range(n):
        for j in syugo:
            if i - j ==0 :
                dp[i] = dp[i] + 1
            elif i - j  > 0:
                dp[i] = dp[i] + dp[i-j]
    ##    rec(n-1)

    print(dp[n-1]%998244353)
main()

