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

long long next(long long x)
{
  string s1 = to_string(x);
  sort(s1.begin(), s1.end());
  string s2 = s1;
  reverse(s2.begin(), s2.end());
  return stoll(s2) - stoll(s1);
}

long long rec(long long n, int i, int k)
{
  if (i == k)
  {
    return n;
  }
  return rec(next(n), i + 1, k);
}

int main()
{
  long long n, k;
  cin >> n >> k;
  cout << rec(n, 0, k) << endl;
}
#include<iostream>
#include<sstream>

using namespace std;

int main() {
	long long n,k;
	cin >> n >> k;
	while(k--){
		if(n % 200 == 0){
			n/=200;
		}else{
			string str = "";
			stringstream ss;
			ss << n;
			ss >> str;
			str += "200";
			stringstream ss1;
			ss1 << str;
			ss1 >> n;
		}
	}
	cout << n;
	return 0;
}