Apply binary search on the answer, one only needs to check whether N can be represented as the sum of M increasing numbers. The key observation is that a number is increasing if and only if it can be represented as the sum of exactly 9 repunits, where a repunit is a number in the form 0 or 11\cdots1. Therefore, one only needs to check whether N can be represented as the sum of 9M repunits. Since all repunits has the form of \dfrac{10^K-1}{9}, the condition holds if and only if 9N can be represented as the sum of 9M numbers of the form 10^K-1, which is equivalent to whether the digit sum of 9N+9M is no more than 9M. This can be easily checked. With a trivial greedy algorithm which decreases the number by the maximum possible repdigit, one can easily show that the answer has an upper bound of O(\log N). Therefore, the problem can be solved in the time complexity of O(\log N\log \log N).