n,k = map(int,input().split()) an = sorted(list(map(int,input().split())))[::-1] count = an[0] i_c = 0 for i in range(1,len(an)): if an[i]<0 or i_c>k: break else: count+=an[i] i_c+=1 print(count)