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

typedef long long int ll;
typedef long double ld;
#define benq queue
#define pbenq priority_queue
#define all(x) x.begin(), x.end()
#define sz(x) (ll)x.size()
#define m1(x) memset(x, 1, sizeof(x))
#define m0(x) memset(x, 0, sizeof(x))
#define inf(x) memset(x, 0x3f, sizeof(x))
#define MOD 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define PI 3.14159265358979323846264338
#define flout cout << fixed << setprecision(12)
ll n, k;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    ll cur = n;
    while(k--) {
        string s = to_string(cur), t = s;
        sort(all(s));
        sort(all(t), greater<char>());

        cur = stoll(t) - stoll(s);
    }

    cout << cur << '\n';
    return 0;
}

// Problem : B - Quadruple
// Contest : AtCoder - AtCoder Regular Contest 107
// URL : https://atcoder.jp/contests/arc107/tasks/arc107_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
	int n, k;
	cin >> n >> k;
	auto f = [&](int x) -> long long{
		if(x < 2 || x > 2 * n) return 0;
		return min(0ll + x - 1, 1ll * 2 * n - x + 1);
	};
	ll ans = 0;
	for(int i = 2; i <= 2 * n; i ++){
		ans += f(i) * f(i + k);
	}
	cout << ans << endl;
	return 0;
}
