fn main() { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); let mut n: Vec = s.split_whitespace().flat_map(str::parse).collect(); let mut a = 0; while n[0] > 0 { a += 1; n[0] /= n[1]; } println!("{}", 2u64.pow(a) - 1); }