n,k=map(int,input().split()) lst=sorted(map(int,input().split()),reverse=True) new_lst=[i for i in lst if i>=0] print(new_lst[0] if new_lst[0]<0 else sum(new_lst[:k]))