use std::collections::HashSet;
use std::cmp::max;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// fn main() {
//     input! {
//         S: chars,
//         T: chars,
//         n: i32,
//         m: i32,
//         U: chars
//     }
//     if S == U {
//         println!("{} {}", n-1, m);
//     } else {
//         println!("{} {}", n, m-1);
//     }
// }

/*
fn main() {
    input! {
        S: chars
    }
    let L = S.len();
    for i in 0..L {
        print!("x");
    }
    println!();
}*/

/*
fn main() {
    input! {
        N: usize,
        A: [i64; N],
    }
    let mut H = HashSet::new();
    for a in &A {
        H.insert(a);
    }
    if H.len() == A.len() {
        println!("YES");
    } else {
        println!("NO");
    }
}*/

/*
fn main() {
    input! {
        N: usize,
        K: usize,
        P: [f64; N]
    }
    let mut tmp = 0.0;
    for i in 0..K {
        tmp += (P[i]+1.0)/2.0;
    }
    let mut ans = tmp;
    for i in K..N {
        tmp += (P[i]+1.0)/2.0 - (P[i-K]+1.0)/2.0;
        if ans < tmp {
            ans = tmp;
        }
    }
    println!("{}", ans);
}*/

fn main() {
    input! {
        N : chars,
        K : usize
    }
    let L = N.len();
    let mut dp = vec![vec![vec![0; 2]; K+2]; L+1];
    dp[0][0][0] = 1;
    for i in 0..L {
        let num = N[i] as i32 - 48;
        //println!("{}", num);
        for k in 0..(K+1) {
            for n in 0..10 {
                for isless in 0..2 {
                    if n != 0 {
                        if isless == 1 || n == num {
                            dp[i+1][k+1][isless] += dp[i][k][isless];
                        } else if n < num {
                            dp[i+1][k+1][1] += dp[i][k][isless];
                        }
                    } else {
                        if isless == 1 || n == num {
                            dp[i+1][k][isless] += dp[i][k][isless];
                        } else if n < num {
                            dp[i+1][k][1] += dp[i][k][isless];
                        }
                    }
                }
            }
            //println!("{} {} {}", k, dp[i+1][k][0], dp[i+1][k][1]);
        }
    }
    
    println!("{}", dp[L][K][1] + dp[L][K][0]);
}

Measured memory_bytes: 4352