mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline N, K = map(int, input().split()) A = list(map(int, input().split())) A.sort(reverse=True) ans = 0 for k in range(K): if A[k] > 0: ans+= A[k] print(ans) if __name__ == '__main__': main()