#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int g1(string s)
{
  sort(s.begin(), s.end(), greater<char>());
  return stoi(s);
}

int g2(string s)
{
  sort(s.begin(), s.end());
  return stoi(s);
}


int main()
{
  string n;
  int ak;
  cin>>n>>ak;
  int size = ak+1;
  string dp[size]{};
  dp[0] = n;
  
  for(int k = 1; k < size; k++)
  {
      dp[k] = to_string(g1(dp[k-1]) - g2(dp[k-1]));
      if(dp[k] == dp[k-1])
        {
            k++;
            for(;k < size; k++)
                dp[k] = dp[k-1];
        }
  }
 
  if(ak == 0)
    cout<<dp[0];
  else
  {
    cout<<dp[ak];
  }
  
}

#include <bits/stdc++.h>

using namespace std;

#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define PI (acos(-1.0))
#define EPS 1e-9
#define INF 0x3f3f3f
//#define int ll
//int：4e10 ll:9e18 ull:1e20 __int128:3e38

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef __int128 lll;

const int maxn = 100010;
const ll mod = 1e9 + 7;
int d[8][2] = {{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,-1},{-1,1}};

template <typename T>
inline T
read() {  // 声明 template 类,要求提供输入的类型T,并以此类型定义内联函数 read()
    T sum = 0, fl = 1;  // 将 sum,fl 和 ch 以输入的类型定义
    int ch = getchar();
    for (; !isdigit(ch); ch = getchar())
        if (ch == '-') fl = -1;
    for (; isdigit(ch); ch = getchar()) sum = sum * 10 + ch - '0';
    return sum * fl;
}

void solve(){

}
int main(){
    IOS;
    double oldp, newp;
    cin >> oldp >> newp;
    cout << ((oldp - newp) / oldp) * 100;
    return 0;
}