# coding: utf-8 N,K = gets.split(' ').map{|s|s.to_i} A = gets.split(' ').map{|s|s.to_i} topK = A.sort!{|l, r| r <=> l} .take(K) if topK[0] < 0 then p topK[0] else p topK.select{|i| i > 0} .sum() end