N,K,*A=map(int,open(0).read().split());print(max(A)if max(A)<0else sum(sorted(list(filter(lambda x:x>0,A)),reverse=True)[:K]))