#include <bits/stdc++.h>
using namespace std;

const int maxDigits = 105;
const int maxDiv = 100*1000 + 5;
string target; // N
int divi; // M
int nbDigits; // D
int dp[maxDigits][maxDiv]; // i first digits set, current val (X mod M) = j
int pow10[maxDigits];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> target >> divi;
	nbDigits = target.size();
	for (int valMod = 1; valMod < divi; ++valMod) {
		dp[nbDigits][valMod] = maxDigits; // Considered to be INF
	}
	dp[nbDigits][0] = 0; // Final state we must reach

	pow10[0] = 1;
	for (int expo = 1; expo < maxDigits; ++expo) {
		pow10[expo] = (pow10[expo-1] * 10) % divi;
	}

	// Slow part
	for (int iDigit = nbDigits-1; iDigit >= 0; --iDigit) {
		int targetDigit = (target[iDigit] - '0');
		int corPow = pow10[nbDigits-1-iDigit];
		for (int origVal = 0; origVal < divi; ++origVal) {
			int res = maxDigits;
			int newVal = origVal;
			for (int digitChoice = 0; digitChoice < 10; ++digitChoice) {
				if (iDigit > 0 || digitChoice > 0) { // Don't put a leading 0!
					int subRes = dp[iDigit+1][newVal];
					if (digitChoice != targetDigit) ++subRes;
					if (subRes < res) res = subRes;
				}

				// Avoid multiplying, add at each iteration instead!
				newVal += corPow;
				// Avoid modulo, substract instead! (faster)
				if (newVal >= divi) newVal -= divi;
			}
			dp[iDigit][origVal] = res;
		}
	}

	// Reconstruction of X
	string answer;
	int curDigit = 0, curVal = 0;
	while (curDigit < nbDigits) {
		int targetDigit = (target[curDigit] - '0');
		int opt = -1;
		int corPow = pow10[nbDigits-1-curDigit];

		for (int digitChoice = 9; digitChoice >= 0; --digitChoice) { // Decreasing order -> put minimal optimal digit
			int newVal = (curVal + digitChoice*corPow)%divi;
			if (curDigit > 0 || digitChoice > 0) {
				int subRes = dp[curDigit+1][newVal];
				if (digitChoice != targetDigit) ++subRes;
				if (dp[curDigit][curVal] == subRes) {
					opt = digitChoice;
				}
			}
		}

		answer.push_back(opt + '0');
		++curDigit;
		curVal = (curVal + opt*corPow)%divi;
	}

	cout << answer << '\n';
}
