from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify from bisect import bisect_left,bisect_right import sys,math,itertools,pprint,fractions sys.setrecursionlimit(10**8) mod = 998244353 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) def inpl_1(): return list(map(lambda x:int(x)-1, sys.stdin.readline().split())) def inplm(): return map(int, sys.stdin.readline().split()) def inpl_1m(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) def err(x): print(x); exit() n,k = inpl() a = inpl() print(sum(sorted(a[1:],reverse=True)[:k]))