// ~maqsat~

// #pragma GCC target ("avx2")
// #pragma GCC optimize ("Ofast")
// #pragma GCC optimize ("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define F first
#define S second
#define in insert
#define pb push_back
#define eb emplace_back
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define count1 __builtin_popcountl
#define debug(x) cerr << (#x) << " = " << (x) << "\n"
#define ACCELERATE ios_base::sync_with_stdio(false),cin.tie(nullptr)
#define fre(f) if(fopen(f".in", "r")) freopen(f".in", "r", stdin),freopen(f".out", "w", stdout)
#define ever ;;

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

using ll = long long;
using ull = unsigned long long;
// using big = __int128_t; // -10^38...10^38
using db = double;
using ld = long double;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> inline void cmin(T &a, T b) { a = min(a, b); }
template <class T> inline void cmax(T &a, T b) { a = max(a, b); }

const int oo = 0x3f3f3f3f;
const ll N = 2e5 + 123;
const ll MOD = 1e9 + 7;
const ll INF = 1e15 + 9;
const db EPS = 1e-9;
const db PI = acos(-1); // 3.14159265358979323846
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

#define int ll

struct bigint {

    static const long long BASE = 1e9;
    static const long long SIZE = 50;

    long long digits[SIZE];

    bigint() {
        for (int i = 0; i < SIZE; i++) {
            digits[i] = 0;
        }
    }

    bigint(long long x) {
        for (int i = 0; i < SIZE; i++) {
            digits[i] = 0;
        }

        int next = 0;
        while (x) {
            digits[next++] = x % BASE;
            x /= BASE;
        }
    }

    bigint(const bigint& other) {
        for (int i = 0; i < SIZE; i++) {
            digits[i] = other.digits[i];
        }
    }

    bigint& operator=(const bigint& other) {
        for (int i = 0; i < SIZE; i++) {
            digits[i] = other.digits[i];
        }

        return *this;
    }
    void operator+=(const bigint& other) {
        for (int i = 0; i < SIZE; i++) {
            digits[i] += other.digits[i];
        }

        for (int i = 0; i < SIZE - 1; i++) {
            if (digits[i] >= BASE) {
                digits[i] -= BASE;
                digits[i + 1]++;
            }
        }
    }

    bigint operator+(const bigint& other) {
        bigint n(*this);
        n += other;
        return n;
    }

    bigint& operator++() {
        *this += 1;
        return *this;
    }
};

ostream& operator<<(ostream& out, const bigint& num) {
    string result;

    char buffer[10];

    for (int i = bigint::SIZE - 1; i >= 0; i--) {
        sprintf(buffer, "%09d", num.digits[i]);
        result += buffer;
    }

    int first_idx = result.find_first_not_of('0');
    if (first_idx == string::npos) {
        out << "0";
    } else {
        out << result.substr(first_idx);
    }

    return out;
}

main() {
#ifdef ZVER
	cerr << "Ready\n";
#endif
	fre("");
	ACCELERATE;
	
	string s;
	cin >> s;
	
	int k;
	cin >> k;
	
	if (k == 1) {
		ll ans = 0;
		for (int i = 0; i < sz(s); i++) {
			if (!i) ans += s[i] - '0';
			else ans += 9;
		}
		cout << ans;
	}
	else if (k == 2) {
		ll ans = 0;
		for (int i = 0; i < sz(s); i++) {
			for (int j = i + 1; j < sz(s); j++) {
				if (!i) {
					ans += (s[i] - '0' - 1) * 9;
					if (j == 1) ans += s[j] - '0';
					else ans += 9;
				}
				else ans += 81;
			}
		}
		cout << ans;
	}
	else {
		bigint ans = 0;
		for (int i = 0; i < sz(s); i++) {
			for (int j = i + 1; j < sz(s); j++) {
				for (int ii = j + 1; ii < sz(s); ii++) {
					if (!i) {
						bigint x = (s[i] - '0' - 1ll) * 81ll;
						ans += x;
						if (j == 1) {
							bigint y = (s[j] - '0' - 1ll) * 9ll;
							ans += y;
							if (ii == 2) ans += bigint(s[ii] - '0');
							else ans += bigint(9ll);
						}
						else ans += bigint(81ll);
					}
					else ans += bigint(9ll * 81ll);
				}
			}
		}
		cout << ans;
	}
	
	return 0;
}
