n, k = list(map(int, input().split(" "))) a = list(map(int, input().split(" "))) a = list(reversed(sorted(a))) ans = a[0] for i in range(1, k): if a[i] <= 0: break ans += a[i] print(ans)