import sys sys.setrecursionlimit(100000000) input = sys.stdin.readline MOD = 10 ** 9 + 7 INF = 10 ** 15 def main(): N,K = map(int,input().split()) A = list(map(int,input().split())) A.sort(reverse=True) ans = 0 for i in range(K): if A[i] > 0: ans += A[i] print(ans) if __name__ == '__main__': main()