use std::io; fn main() { let mut s1 = String::new(); io::stdin().read_line(&mut s1).ok(); let mut nk: Vec = s1.trim().split_whitespace() .map(|e| e.parse().ok().unwrap()).collect(); let mut s2 = String::new(); io::stdin().read_line(&mut s2).ok(); let mut a: Vec = s2.trim().split_whitespace() .map(|e| e.parse().ok().unwrap()).collect(); a.sort(); a.reverse(); let mut ans = 0i32; for i in 0..nk[1] { if a[i] > 0 { ans += a[i]; } } println!("{}", ans); }