n, k = map(int, input().split()) a = sorted(list(map(int, input().split())), reverse=True) ans = 0 for i in range(k): ans += max(0, a[i]) print(ans)