import sys sys.setrecursionlimit(10 ** 8) input = sys.stdin.readline def main(): N, K = [int(x) for x in input().split()] A = [int(x) for x in input().split()] A.sort(reverse=True) ans = A[0] for i in range(1, K): if A[i] <= 0: break ans += A[i] print(ans) if __name__ == '__main__': main()