#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < (n);i++) 
using namespace std;

int main() {
    
    int  k;
    string n;
   
    cin >> n >> k;

    string s = n;
    rep(i,k) {  

        string s1,s2;

        sort(s.begin(), s.end());
        s1 = s;
        sort(s.begin(), s.end(), greater<char>());
        
        s2 = s;

        int x = stoi(s2) - stoi(s1);

        s = to_string(x);

    }   

    cout << s << endl;

}
#include <iostream>
using namespace std;

int main() {
  
	int a;
  cin >> a;
  
  int b;
  cin >> b;
  
  int c;
  c = 2 * a + 100 - b;
  
  cout << c;
  
	return 0;
}
