Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

My Small Number

By IamHot · Limits 1s, 512 MB

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.

Here, the same number of digits mean the number of positions where there the two numbers have same digits. For example, the numbers “123” and “321” have 1 same digit in the second position.

The length of a number will be considered without leading zeroes.

Input

Input contains two space-separate integers N and M without leading zeroes.

  • 10 ≤ N ≤ 10100
  • 1 ≤ M ≤ 105 , M ≤ N

Output

Output one line containing integer X as described above, without leading zeroes.

Samples

InputOutput
10 5
10
InputOutput
10 7
14


Discussion
Statistics

46% Solution Ratio

Optimised_TLEEarliest, 3w ago

SaikatSFastest, 0.4s

mahdi.hasnatLightest, 40 MB

zarif2Shortest, 956B

Submit

Login to submit