import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) n, k, *a = map(int, read().split()) a.sort() ans = max(a) for i in range(n): if a[0] < 0: a.pop(0) else: break a.sort(reverse=True) print(max(ans, sum(a[:k])))