123=0
4235=0
656=2
5390=2
8890=6
1001=2
19235=1
The logic explanation to the above sequence is that the right hand side is equal to the total number of closed circles appearing in all the digits on the left hand side.
Therefore by using the same concept, 123456789 = 4