#import numpy as np import sys from collections import defaultdict read = sys.stdin.buffer.read readline = sys.stdin.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(100) n , k = map(int,input().split()) A = list(map(int,input().split())) fruit = sorted(A , reverse= True) delicious = 0 index = 0 number_fruit = 0 while number_fruit < k and index < n: if fruit[index] > 0 : delicious += fruit[index] number_fruit += 1 else: break index += 1 print(delicious)