import math from math import sqrt import sys from collections import deque, defaultdict from heapq import heappop, heappush from copy import deepcopy INF=10**18 MOD=10**9+7 MAX=10**5+7 #N,K=map(int, input().split()) #A=list(map(int, input().split())) def main(): N,K=map(int, input().split()) A = list(map(int, input().split())) A.sort() A=A[::-1] ans=0 for i in range(K): if A[i]>0: ans+=A[i] print(ans) if __name__ == '__main__': main()