def main(): n, k = map(int, input().split()) A = sorted(map(int, input().split())) if A[-1] < 0: print(A[-1]) *A, = filter(lambda x: x > 0, A) print(sum(A[:min(len(A), k)])) if __name__ == '__main__': main()