#!/usr/bin/env python3 def optimize(n, k, bs): cs = sorted((b for b in bs if b >= 0), reverse=True) return sum(cs[:k]) def main(): n, k = (int(z) for z in input().split()) bs = [int(b) for b in input().split()] res = optimize(n, k, bs) print(res) if __name__ == "__main__": main()