#include <bits/stdc++.h>
using namespace std;
int main() {
  string n;
  cin >> n;
  int k;
  cin >> k;
  long long int ans = 0L;
  long long int d = n.size();
  if (k == 3) {
    for (int i = 1; i <= d; i++) {
      for (int j = 1; j < i; j++) {
        for (int l = 1; l < j; l++) {
          if (i == d) {
            ans += (n[d - i] - '0' - 1) * 9 * 9;
            bool f = false;
            for (int m = d - i + 1; m < d - j; m++) {
              if (n[m] != '0') {
                f = true;
                break;
              }
            }
            if (f) {
              ans += 9 * 9;
            } else {
              ans += (n[d - j] - '0' - 1) * 9;
              bool fl = false;
              for (int o = d - j + 1; o < d - l; o++) {
                if (n[o] != '0') {
                  fl = true;
                  break;
                }
              }
              if (f) {
                ans += 9;
              } else {
                ans += n[d - l] - '0';
              }
            }
          } else {
            ans += 9 * 9 * 9;
          }
        }
      }
    }
  } else if (k == 2) {
    for (int j = 1; j <= d; j++) {
      for (int l = 1; l < j; l++) {
        if (j == d) {
          ans += (n[d - j] - '0' - 1) * 9;
          bool f = false;
          for (int m = d - j + 1; m < d - l; m++) {
            if (n[m] != '0') {
              f = true;
              break;
            }
          }
          if (f) {
            ans += 9;
          } else {
            ans += n[d - l] - '0';
          }
        } else {
          ans += 9 * 9;
        }
      }
    }
  } else {
    for (int l = 1; l <= d; l++) {
      if (l == d) {
        ans += n[d - l] - '0';
      } else {
        ans += 9;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
