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