#!/usr/bin/env python3
def main():
    import numpy as np

    N, K = map(int, input().split())
    S = set()
    section = []
    for _ in range(K):
        l, r = map(int, input().split())
        section.append((l, r + 1))
        for n in range(l, r + 1):
            S.add(n)
    MOD = 998244353

    dp = np.zeros(N, dtype=np.int64)
    dp[0] = 1
    for i in range(N):
        # for d in S:
        #     if i >= d:
        #         dp[i] += dp[i - d] % MOD
        for left, right in section:
            right = min(i + right, N)
            left = i + left
            dp[left:right] += dp[i]
    print(dp[-1] % MOD)
    # print(dp)


if __name__ == '__main__':
    main()
