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

string n;
int k;
string res;
//-----------
bool cmp(char a, char b)
{
    return a>b;
}
//-----------
string inttostring(long long n)
{
    stringstream stream;
    stream<<n;
    string st=stream.str();
    return st;
}
//--------------------------------
long long stringtoint(string m)
{
    long long k=atoll(m.c_str());
    return k;
}
//------------------------------
int main()
{
    cin>>n>>k;
    res=n;
    while (k--)
    {
        string a=res,b=res;
        int x,y,z;
        sort(a.begin(),a.end());
        sort(b.begin(),b.end(),cmp);
        x=stringtoint(a);
        y=stringtoint(b);
        z=y-x;
        res=inttostring(z);
    }
    cout<<res;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back 
#define mp make_pair
#define asort(a,n) sort(a,a+n)
#define vsort(v) sort(v.begin(),v.end())
#define all(v) v.begin(),v.end()
#define run ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0);
#define mod 1000000007
#define endl "\n" 
#define LL_MAX LLONG_MAX
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl

//********************************* mekch ************************************//

ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 

ll binExp(ll x,ll n)
{
   ll res=1;
    while(n)
    {
        if(n&1) res=(res*x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return res;
}

bool isPerfectSquare(long double x) 
{   
  long double sr = sqrt(x); 
  
  return ((sr - floor(sr)) == 0); 
} 
  
int main()
 {
  run;
  ll t;
 
     
  // ALWAYS UES LL_MAX    
  long double  n,i,x,y,ok=0,sum=0,ans=0,res;
  ll res1,res2,res3,res4;

        cin>>x>>y;
        res=x*x-4*y;
    if (isPerfectSquare(res)) 
    {
        res1=sqrt(res);
        res2=x+res1;
        res3=x-res1;
       // cout<<"jdc";
        
        if(res2%2==0)
          res2=res2/2;
          else
          res2=-1;
          if(res3%2==0)
            res3=res3/2;
            else
            res3=-1;
            
            if(res2>0||res3>0)
            {
                if(res2>0)
                res4=x-res2;
                else
                res4=x-res3;
                
                if(res4>0)
                yes;
                else
                no;
            }
        else
        no;
    }
    else
    no;
   
  
 }