Problem #329
Use Calculator
Consider a number in base 10,without leading zeros (zero is taken as 0), written as digits made from identical straight segments.
Now in each operation, we are allowed to move or even rotate any of these segments such that the final picture obtained is also a number.
For example, the number 69 has total 12 segments, so it can be changed to 427, which has 12 segments too.
Let M(n) denote the largest number which can be obtained from n using any number of such operations. Also, let S(n) denote the sum of digits of n in base 10.
Find :
where N\:=\:10^{2023}-1