n,k=map(int,input().split()) a=sorted(list(map(int,input().split())))[::-1] for i in range(n): a[i] = max(a[i],0) print(sum(a[0:k]))