#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb emplace_back 
#define mp make_pair
#define fi first
#define se second
#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 decimal(k) cout<<fixed<<setprecision(k)<<endl
#define LL_MAX LLONG_MAX
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
int exp(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int modinv(int x){return exp(x,mod-2);}
int add(int a,int b){a%=mod,b%=mod;a=((a+b)%mod+mod)%mod;return a;}
int sub(int a,int b){a%=mod,b%=mod;a=((a-b)%mod+mod)%mod;return a;}
int mul(int a,int b){a%=mod,b%=mod;a=((a*b)%mod+mod)%mod;return a;}
int gcd(int a, int b){if (b == 0)return a; return gcd(b, a % b);}
int Log2n( int n){ return (n > 1) ? 1 + Log2n(n / 2) : 0;} 
int fac[100009];int ncr_mod(int n,int k){int ans=fac[n];ans*=modinv(fac[k]);ans%=mod;ans*=modinv(fac[n-k]);ans%=mod;return ans;}
vector<int>v_prime;void Sieve(int n){bool prime[n + 1];memset(prime,true,sizeof(prime));for (int p = 2; p*p <=n;p++){if(prime[p] ==true) {for(int i = p*p; i<= n; i += p)prime[i]=false;}}for(int p = 2;p<= n;p++)if (prime[p])v_prime.pb(p);}
vector<int>v_factor;void factors(int n){ for (int i=1; i<=sqrt(n); i++) {if (n%i == 0) {if (n/i == i) v_factor.pb(i);else { v_factor.pb(i),v_factor.pb(n/i);};} } sort(all(v_factor)); } 
void out(vector<int>&a){for(int i=0;i<a.size();i++) cout<<a[i]<<" ";  cout<<endl;} 


// s.top().second;


signed main()
 {


       run;


/*
open for mod factorial

     fac[0]=1;
       for(int i=1;i<100009;i++)
      {
         fac[i]=fac[i-1]*i; 
          fac[i]%=mod;  
      }
 */


/*
for sieve open this and use v_prime

       int pp=pow(10,6)+100000; 
          Sieve(pp);

*/


 // USE v_factor For calculating factors                       


int  t=1;
 //cin>>t;
 while(t--)
{
         // vector< pair <int,int> > vp; 
        //  map<int,int>mp; // x.second-->frequency
       //   set<int>st;


          int  n,i,x,y,ok=0,sum=0,ans=0,j,k,cnt=0,m,c=0;
          int  h[100009]={0};


                cin>>n>>k;
                if(k==0)
                {
                    cout<<n<<endl;
                    return 0;
                }
                string s=to_string(n);
                sort(all(s));
                x=stoi(s);
                //cout<<x<
                reverse(all(s));
                y=stoi(s);
                vector<int>a(k+2,0);

                for(i=1;i<=k;i++)
                {

                        a[i]=y-x;

                         string s1=to_string(a[i]);
                sort(all(s1));
                x=stoi(s1);
                reverse(all(s1));
                y=stoi(s1);
              



                }
                cout<<a[k]<<endl;

               
}
}
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
//#define int long long
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PI = pair<pair<int,int>,int>;
using PL = pair<long long, long long>;
using PLL = pair<pair<long long, long long>, long long>;
using Pxy = pair<long double, long double>;
using Tiib = tuple<int, int, bool>;
const int INF = 1001001007;
const int modd = 1000000007;
const long long modl = 1000000007LL;
const long long mod = 998244353LL;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(){
    cout << "Yes" << endl;
}

void no (){
    cout << "No" << endl;
}

ll cel (ll a, ll b){
    if (a % b == 0) return a / b;
    else return a / b + 1;
}

ll gcds(ll a, ll b){
    ll c = a % b;
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

int main(){
    int n; cin >> n;
    ll w; cin >> w;
    vector<vector<ll>> ar(n,vector<ll>(3));
    rep(i,n) rep(j,3) cin >> ar[i][j];
    vector<ll> imo(200010,0LL);
    rep(i,n){
        imo[ar[i][0]] += ar[i][2];
        imo[ar[i][1]] -= ar[i][2];
    }
    bool t = true;
    ll rui = 0LL;
    rep(i,200010){
        rui += imo[i];
        if (rui > w) t = false;
    }
    if (t) yes();
    else no();
}