n,k=map(int,input().split()) a = list(map(int,input().split())) a = list(filter(lambda x:x>0, a)) print(sum(a[-k:]))