#yuki1046 n,k=map(int,input().split()) a=list(map(int,input().split())) b=sorted(a,reverse=True) if b[0]<=0: print(b[0]) else: res=0 for i in range(k): if b[i]>0: res+=b[i] print(res)