#Lutece1039. Fabricate equation

Fabricate equation

Migrated from Lutece 1039 Fabricate equation

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

Given an integer YY, you need to find the minimal integer KK so that there exists a XX satisfying XY=Z(Z0)X - Y = Z (Z \geq 0) and the number of different digit between XX and ZZ is KK under decimal system.

For example: Y=1Y = 1, you can find a X=100X = 100 so that Z=99Z =99 and KK is 33 due to 101 \neq 0 and 090 \neq 9. But for minimization, we should let X=1X = 1 so that Z=0Z = 0 and KK can just be 11.

Input

Only one integer Y(0Y1018).Y (0 \leq Y \leq 10^{18}).

Output

The minimal KK.

Samples

1
1
191
2

Resources

The 13th UESTC Programming Contest Preliminary