Finding an integer

Find the smallest integer at least N whose decimal digits contain d1 at least c1 times and d2 at least c2 times.

Hard8GreedyImplementationBrute forceMathInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

Consider the natural numbers greater than or equal to NN whose decimal representation contains the digit d1d_1 at least c1c_1 times and the digit d2d_2 at least c2c_2 times.

Write a program that finds the smallest such number.

Input

The first line contains NN, d1d_1, c1c_1, d2d_2, c2c_2, separated by spaces. (1N<10151 \le N < 10^{15}, 0d1,d290 \le d_1, d_2 \le 9, d1d2d_1 \ne d_2, 0c10 \le c_1, 0c20 \le c_2, c1+c215c_1 + c_2 \le 15)

Output

Print the smallest number that satisfies the condition on the first line. The answer fits in a 64-bit integer.