#!/usr/bin/env python3
import sys

MOD = 998244353  # type: int


def solve(N: int, K: int, L: "List[int]", R: "List[int]"):
    dp = [0] * (N + 1)
    dp[1] = 1
    # s = []
    # for i in range(K):
    #     for j in range(L[i], R[i]+1):
    #         s.append(j)
    # s.sort()
    for i in range(1, N+1):
        # for j in s:
        for s in range(K):
            for j in range(L[s], R[s]+1):
                if i - j >= 1:
                    dp[i] += dp[i-j]
                    dp[i] %= MOD
                else:
                    break
    print(dp[N]%MOD)

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    L = [int()] * (K)  # type: "List[int]"
    R = [int()] * (K)  # type: "List[int]"
    for i in range(K):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))
    solve(N, K, L, R)

if __name__ == '__main__':
    main()
