import sys
import math


def input():
    return sys.stdin.readline().rstrip()


def main():
    N,K=map(int,input().split())
    L=list()
    for i in range(K):
        l,r=map(int,input().split())
        for j in range(l,r+1):
            L.append(j)
    mod=998244353
    L.sort()

    dp=[0]*(N+1)
    dp[0] =1
    for i in range(N):

        for l in L:
            if i+l>N:
                break
            dp[i+l] +=dp[i]
            dp[i+l] %=mod

    print(dp[N-1])













if __name__ == "__main__":
    main()

# \n
