MOD = 998244353


def main():
    from bisect import bisect_left
    N, K = (int(i) for i in input().split())
    S = set()
    for _ in range(K):
        le, ri = (int(i) for i in input().split())
        for i in range(le, ri+1):
            S.add(i)

    A = sorted(S)
    memo = [0] * (N+1)
    memo[0] = 1

    def dfs(N):
        if N < 0:
            return 0
        if memo[N] != 0:
            return memo[N]
        ret = 0
        idx = bisect_left(A, N)
        for i in A[idx::-1]:
            ret += dfs(N - i)
            ret %= MOD
        memo[N] = ret
        return ret

    print(dfs(N-1))
    # print(memo, A)


if __name__ == '__main__':
    main()
