n, k = map(int, input().split()) A = sorted(list(map(int, input().split())), reverse=True) if A[0] < 0: print(A[0]) exit() res = 0 for i in range(k): if A[i] > 0: res += A[i] print(res)