n,k = list(map(int,input().split())) an = list(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 print(result)