import sys sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n, k = map(int, input().split()) A = sorted(list(map(int, input().split())), reverse=True) res = A[0] for i in range(1, k): if A[i] > 0: res += A[i] print(res) if __name__ == '__main__': resolve()