n, k = read_line.split.map &.to_i a = read_line.split.map(&.to_i).sort.reverse puts a.take_while {|i| i > 0 }[0, k].sum