n,k = map(int,input().split()) ls = list(map(int,input().split())) s = 0 for i in range(ls): if ls[i] <= 0: ls[i] = 0 ls.sort(reverse=True) print(sum(ls[:k]))