import sys
input = sys.stdin.readline
def main():
    N, K = map(int, input().split())
    M = []
    mod = 998244353
    for i in range(K):
        a, b = map(int, input().split())
        for j in range(a, b+1):
            M.append(j)
    M = set(M)
    dp = [0]*(N+1)
    dp[1] = 1
    for i in range(2,N+1):
        for s in M:
            if i-s >= 1:
                dp[i] += dp[i-s]%mod
    print(dp[N]%mod)

if __name__ == '__main__':
    main()