n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort(reverse=True) ans = 0 cnt = False for i in range(k): if a[i] > 0: ans += a[i] cnt = True if cnt: print(ans) else: print(a[0])