import sys readline = sys.stdin.readline N, K = map(int, input().split()) a = sorted(map(int, input().split()), reverse=True) print(sum(max(a[i], 0) for i in range(K)))