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 = 0; for i in 0..k { if a[i] < 0 { break; } ans += a[i]; } println!("{}", ans); }