fn main() { let mut nk = String::new(); std::io::stdin().read_line(&mut nk).ok(); let nk: Vec = nk.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n = nk[0]; let k = nk[1]; let mut a = String::new(); std::io::stdin().read_line(&mut a).ok(); let mut a: Vec = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); a.sort(); let result: isize = a.iter().rev().take(k).filter(|i| **i > 0).sum(); println!("{}", if result == 0 { a[n-1] } else { result }); }