use std::io::Read; fn main() { let mut buf = String::new(); std::io::stdin().read_to_string(&mut buf).unwrap(); let mut iter = buf.split_whitespace(); let n: usize = iter.next().unwrap().parse().unwrap(); let k: usize = iter.next().unwrap().parse().unwrap(); let mut a: Vec = Vec::with_capacity(n); for _ in 0..n { a.push(iter.next().unwrap().parse().unwrap()); } a.sort_by(|x, y| y.cmp(x)); let mut ans = a[0]; for i in 1..k { if a[i] < 0 { break; } ans += a[i]; } println!("{}", ans); }