#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  int len = s.size();
  long long sum = 0;
  if (k == 1) {
    sum = (len - 1) * 9 + (s[0] - '0');
  }
  if (k == 2) {
    if (len > 2) {
      int x = s[0] - '0' - 1;
      int y = 1;
      int index = 0;
      for (int i = 1; i < len; i++) {
        if (s[i] != '0') {
          y = s[i] - '0';
          index = i;
          break;
        }
      }
      if (index != 0) sum += y + (len - 1 - index) * 9;
      if (x != 0) {
        sum += x * (len - 1) * 9;
        for (int i = 1; i < len; i++) {
          for (int j = i + 1; j < len; j++) {
            sum += 81;
          }
        }
      } else {
        for (int i = 1; i < len; i++) {
          for (int j = i + 1; j < len; j++) {
            sum += 81;
          }
        }
      }
    } else {
      int n = (s[0] - '0') * 10 + (s[1] - '0');
      for (int i = 11; i <= n; i++) {
        if (i % 10 != 0) {
          sum++;
        }
      }
    }
  }
  if (k == 3) {
    int x = s[0] - '0' - 1;
    int y = 1;
    bool f = true;
    int index = 0;
    int m = 0;
    for (int i = 1; i < len; i++) {
      if (s[i] != '0' && f) {
        y = s[i] - '0';
        m = y;
        f = false;
      } else if (s[i] != '0' && f == false) {
        y *= s[i] - '0';
        index = i;
        break;
      }
    }
    sum += (len - index - 1) * 9 * m;
    sum += y;
    int num = 0;
    for (int i = index; i < len; i++) {
      for (int j = i + 1; j < len; j++) {
        sum += 81;
      }
    }
    for (int i = 1; i < len; i++) {
      for (int j = i + 1; j < len; j++) {
        num += 81;
      }
    }
    sum += num * x;
    for (int i = 1; i < len; i++) {
      for (int j = i + 1; j < len; j++) {
        for (int l = j + 1; l < len; l++) {
          sum += 9 * 9 * 9;
        }
      }
    }
  }
  cout << sum << endl;
  return 0;
}
