n,k = map(int,input().split()) an = sorted(map(int,input().split()),reversed=True) result = an[0] for i,v in enumerate(an): if i+1<=k and v>0: result+=v elif i+1>k: break print(result)