#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const int mod = 1000000007;
template <typename T>
__attribute__((constructor)) void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
int main() {
  string n;
  cin >> n;
  int k;
  cin >> k;
  if (k == 1) {
    cout << (n[0] - '0') + ((n.size() - 1) * 9) << endl;
  } else if (k == 2) {
    int ans = 0;
    int nw = 81;
    for (int i = 2; n.size() > i; i++) {
      ans += nw * (i - 1);
    }
    ans += (n[0] - '1') * (n.size() - 1) * 9;
    for (int i = n.size() - 1; 0 < i; i--) {
      bool ok = false;
      for (int j = i - 1; 0 < j; j--) {
        if (n[i] != '0') {
          ok = true;
          break;
        }
      }
      if (ok) {
        ans += 9;
      } else {
        ans += n[i] - '0';
      }
    }
    cout << ans << endl;
  } else {
    long long ans = 0;
    long long nw = 81 * 9;
    long long z = 1;
    for (int i = 3; n.size() > i; i++) {
      long long tmp = 0;
      for (int j = 0; i - 2 > j; j++) {
        tmp += ((j + 1) * 9) * 9;
      }
      ans += (tmp * 9);
    }
    {
      long long tmp = 0;
      for (int j = 0; n.size() - 2 > j; j++) {
        tmp += ((j + 1) * 9) * 9;
      }
      ans += (n[0] - '1') * tmp;
    }
    for (int i = n.size() - 1; 0 < i; i--) {
      for (int j = i - 1; 0 < j; j--) {
        bool ok = false;
        for (int k = j - 1; 0 < k; k--) {
          if (n[k] != '0') {
            ok = true;
            break;
          }
        }
        if (ok) {
          ans += 81;
        } else {
          if (n[j] == '0') {
            bool nya = false;
            for (int k = i - 1; j < k; k--) {
              if (n[k] != '0') {
                nya = true;
                break;
              }
            }
            if (nya) {
              ans += 9;
            } else {
              ans += n[i] - '0';
            }
          } else {
            ans += ((n[j] - '1') * 9 + (n[i] - '0'));
          }
        }
      }
    }
    cout << ans << endl;
  }
}
