/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using VecVec = vector<Vec>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
template <typename T>
void co(const T n){cout << n << endl;}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << endl;}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); cout << endl;}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); cout << endl;}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;

ll count(){
	ll res = 0;

	rep(i, 1000){
		ll a, b, c, n = i;
		a = n%10;
		n /= 10;
		b = n%10;
		c = n/10;
		if(!a || !b || !c) continue;
		res++;
	}

	return res;
}

bool f(ll n, ll i, ll j, ll k, string s){
	ll a, b, c;
	a = n%10;
	n /= 10;
	b = n%10;
	c = n/10;
	if(!a || !b || !c) return false;
	string t;
	rep(i, s.size()) t += '0';
	t[i] = a+'0';
	t[j] = b+'0';
	t[k] = c+'0';
	return t < s;
}

int main(void){
	string s;
	cin >> s;
	ll n;
	cin >> n;

	ll l = s.size(), p = count();

	ll ans = 0;
	if(n == 3)
	rep(i, l-2){
		REP(j, i+1, l-1){
			REP(k, j+1, l){
				if(!f(111, i, j, k, s)){
					continue;
				}else if(f(999, i, j, k, s)){
					ans += p;
					continue;
				}
				REP(m, 111, 1000){
					ll a, b, c, z = m;
					a = z%10;
					z /= 10;
					b = z%10;
					c = z/10;

					if(!a || !b || !c) continue;
					string t;
					rep(i, s.size()) t += '0';
					t[i] = a+'0';
					t[j] = b+'0';
					t[k] = c+'0';
					if(s >= t) ans++;
				}
			}
		}
	}
	else if(n == 2)
	rep(i, l-1){
		REP(j, i+1, l){
			rep(m, 100){
				ll a, b, z = m;
				a = z%10;
				b = z/10;
				if(!a || !b) continue;
				string t;
				rep(i, s.size()) t += '0';
				t[i] = a+'0';
				t[j] = b+'0';
				if(s >= t){
					ans++;
				}
			}
		}
	}
	else
	rep(i, l){
		rep(m, 10){
			ll a, z = m;
			a = z%10;
			if(!a) continue;
			string t;
			rep(i, s.size()) t += '0';
			t[i] = a+'0';
			if(s >= t){
				ans++;
			}
		}
	}

	co(ans);

	return 0;
}


Measured memory_bytes: 256