fn main() { let mut xx = String::new(); std::io::Read::read_to_string(&mut std::io::stdin(), &mut xx).ok(); let xx: Vec<&str> = xx.split_whitespace().collect(); let k: usize = xx[1].parse().unwrap(); let mut xx: Vec = xx[2..].iter().map(|&n| n.parse().unwrap()).collect(); xx.sort_unstable(); xx.reverse(); let i = k.min(xx.iter().position(|&x| x <= 0).unwrap_or(xx.len())); let answer = xx[..i].iter().sum::(); println!("{}", answer); }