import sys


def main():
    N, K = map(int, sys.stdin.readline().rstrip().split())
    L = [0] * 10
    R = [0] * 10
    for i in range(K):
        l, r = map(int, sys.stdin.readline().rstrip().split())
        L[i], R[i] = l, r

    dp = [0] * (N+1)
    dp[1] = 1
    for i in range(2,N+1):
        for j in range(K):
            l = min(L[j], i)
            r = min(R[j], i)
            dp[i] += sum(dp[i-r:(i-l)+1])
            dp[i] %= 998244353
        # print(dp[i])
    
    print(dp[N])


main()