N, K = map(int, input().split()) A = list(map(int, input().split())) A.sort(reverse=True) cnt = 0 for key, val in enumerate(A): if cnt < cnt + val: cnt += val else: # 小さくなるときbreak break # K個で終了 if key + 1 == K: break print(cnt)