My Small Number

You are given two integers N and M. Find another integer X divisible by M that has the same number of digits as N. If there are multiple such X, then print the one with the least number of digits different from N. If there are still multiple such X, then print the smallest one among them.


This is a companion discussion topic for the original entry at https://toph.co/p/my-small-number