#include <bits/stdc++.h>
#define arraysize(array) (sizeof(array)/sizeof(array[0]))
#define loop(i,a,b) for (int i = a; i < b; i++)
#define loopData(array) (cout << array[i] << " ")

using namespace std;

bool binarySearch(int arra[],int arraySize, int key){
    int startPoint, endPoint;
    int location;

    startPoint = 0;
    endPoint = arraySize - 1;

    while(startPoint <= endPoint){
        int midPoint = (startPoint + endPoint) / 2;

        if(arra[midPoint] == key){
            return true;
            break;
        }
        else if(arra[midPoint] < key){
            startPoint = midPoint + 1;
        }
        else
        {
            endPoint = midPoint - 1;
        }   
    }
    return false;
}

void insert(int arra[], int arraySize, int position, int item){
    for(int i = arraySize - 1; i >= position-1; i--){
        arra[i+1] = arra[i];
    }
    arra[position-1] = item;
}

int main() {
    int M, H;

    cin >> M >> H;

    if(H % M == 0){
        cout << "Yes" << endl;
    }else
    {
        cout << "No" << endl;
    }
}
#include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
using pii = pair<int, int>;
using pll = pair<i64, i64>;
#define rep(i, n) for(i64 i = 0; i < n; i++)
#define per(i, n) for(i64 i = n - 1; i >= 0; i--)
#define REP(i, a, b) for(i64 i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define se second
#define debug(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
template <typename T> ostream& operator<<(ostream& os, const vector<T>& vec) {
    for (auto v : vec) { os << v << ' '; } os << '\n'; return os;
}
template <typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& pa) {
    os << '(' << pa.first << ',' << pa.second << ')'; return os;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
    cerr << " " << H; debug_out(T...);
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1 << 30) - 1;
const i64 LINF = (1LL << 62) - 1;

void solve() {
    i64 n, k;
    cin >> n >> k;
    rep(i, k) {
        string s1 = to_string(n);
        string s2 = to_string(n);
        sort(rall(s1));
        sort(all(s2));
        n = stoll(s1) - stoll(s2);
    }
    cout << n << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}
