use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let n = read_as_string()
        .chars()
        .map(|c| c.to_digit(10).unwrap() as u64)
        .collect::<Vec<u64>>();

    let k = read_as_vec::<usize>()[0];

    if n.len() < k{
        println!("0");
        return;
    }

    if n.len() == 1{
        println!("{}",n[0]);
        return;
    }

    let mut dp0: Vec<Vec<u64>> = vec![vec![0;3];n.len()]; // undecided
    let mut dp1: Vec<Vec<u64>> = vec![vec![0;3];n.len()]; // decided
    dp0[0][0] = 1;
    dp1[0][0] = n[0]-1;

    for i in 1..n.len(){
        if n[i] == 0{
            dp0[i][0] = dp0[i-1][0];
            dp0[i][1] = dp0[i-1][1];
            dp0[i][2] = dp0[i-1][2];
        }else{
            dp0[i][0] = 0;
            dp0[i][1] = dp0[i-1][0];
            dp0[i][2] = dp0[i-1][1];

            dp1[i][0] += dp0[i-1][0];
            dp1[i][1] += (n[i]-1) * dp0[i-1][0] + dp0[i-1][1];
            dp1[i][2] += (n[i]-1) * dp0[i-1][1] + dp0[i-1][2];
        }


        dp1[i][0] += 9 + dp1[i-1][0];
        dp1[i][1] += dp1[i-1][0]*9 + dp1[i-1][1];
        dp1[i][2] += dp1[i-1][1]*9 + dp1[i-1][2];
    }

    dbg!(&dp0);
    dbg!(&dp1);

    println!("{}", dp0[n.len()-1][k-1] + dp1[n.len()-1][k-1]);

}
