#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<62);
const double inf=pow(10,10);
const ld pi=acosl(1);
const ll mod = 1000000007;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};

template< typename T >
T binomial(int64_t N, int64_t K) {
  if(K < 0 || N < K) return 0;
  T ret = 1;
  for(T i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}

ll k1(string n){
	if(n.size()<1)return 0;
	ll ans=0;
	ll d1=(n[0]-'0');
		//zero
		ans+=binomial<ll>((ll)n.size()-1,1)*9;
		//else
		ans+=d1;
	return ans;
}

ll k2(string n){
	if(n.size()<2)return 0;
	ll d2=(n[0]-'0');
	ll ans=0;
		ans+=binomial<ll>((ll)n.size()-1,2)*9*9;
		ans+=max(d2-1,0LL)*binomial<ll>((ll)n.size()-1,1)*9;
		string n2;
		for(int i=1;i<n.size();i++){
			n2.push_back(n[i]);
		}
		ans+=k1(n2);
		return ans;
}

int main(){
	string n;cin>>n;
	ll k;cin>>k;
	ll ans=0;
	if(k==1){
		cout<<k1(n)<<endl;
	}
	if(k==2){
		if(n.size()<2){
			cout<<0<<endl;
			return 0;
		}
		cout<<k2(n)<<endl;
	}
	if(k==3){
		//zero
		if(n.size()<3){
			cout<<0<<endl;
			return 0;
		}
		ll d3=(n[0]-'0');
		ans+=binomial<ll>((ll)n.size()-1,3)*9*9*9;
		ans+=max(d3-1,0LL)*binomial<ll>((ll)n.size()-1,2)*9*9;
		string n2;
		for(int i=1;i<n.size();i++){
			n2.push_back(n[i]);
		}
		ans+=k2(n2);
		cout<<ans<<endl;
	}
}
