use std::io;
use std::str::FromStr;

fn input_char_vec() -> Vec<char> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().chars().collect()
}

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn combination(n: u64, mut m: u64) -> u64 {
    if n < m {
        return 0;
    }
    if m > n - m {
        m = n - m
    }

    let mut ret = 1u64;
    for i in 0..m {
        ret *= n - i;        
    }

    let mut div = 1u64;
    for i in 1..(m+1) {
        div *= i;
    }
    ret / div
}

fn recur(idx: usize, n: &Vec<char>, left: u64) -> u64 {
    if idx == n.len() {
        return 0;
    }
    if left == 0 {
        return 0;
    }
    let d: u64 = n[idx] as u64 - 48;
    let mut tmp = recur(idx+1, n, left-1); // 現在の桁と同じ値をとった場合
    tmp += combination((n.len() - idx - 1) as u64, left - 1) * 9u64.pow(left as u32 - 1) * (d - 1); // 現在の値より小さな値をとった場合
    if left as usize != n.len() - idx {
        tmp += combination((n.len() - idx - 1) as u64, left) * 9u64.pow(left as u32); // 採用しなかった場合
    } 
    tmp
}

fn main() {
    let n = input_char_vec();
    let k: usize = input();

    let d = n.len();
    if k > d {
        println!("0");
        return;
    }
    println!("{}", recur(0, &n, k as u64) + 1);
}
