#import <Foundation/Foundation.h>

int main(int argc, char **argv) {
          NSInteger N, K;
          scanf("%ld %ld", &N, &K);
          NSMutableArray *array = [NSMutableArray new];
          NSInteger capacity = N - K;
  		  if(capacity <= 0) {
            printf("%ld", 0);
            return 0;
          }
        
          int i;
          for(i=0;i<N;i++) {
            NSInteger val;
            scanf("%ld", &val);
            if ([array count] == 0) {
              [array addObject: [NSNumber numberWithInteger: val]];
              continue;
            }
            if ([array count] < capacity) {
              [array addObject:[NSNumber numberWithInteger: val]];
            } else {
              if ([(NSNumber *)[array objectAtIndex: 0] integerValue] <= val) {
                continue;
              }
              [array exchangeObjectAtIndex: 0 withObjectAtIndex: [array count] - 1];
              [array removeObjectAtIndex: [array count] - 1];
              NSInteger current = 0;
              while (current < array.count) {
                NSInteger target = current;
                NSInteger left = target * 2 + 1;
                NSInteger right = left + 1;
                if (left < array.count &&
                    [(NSNumber *)[array objectAtIndex: left] integerValue] <
                    [(NSNumber *)[array objectAtIndex: target] integerValue]) {
                  target = left;
                }
                if (right < array.count &&
                    [(NSNumber *)[array objectAtIndex: right] integerValue] <
                    [(NSNumber *)[array objectAtIndex: target] integerValue]) {
                  target = right;
                }
                if (target == current) {
                  break;
                }
                [array exchangeObjectAtIndex: current withObjectAtIndex: target];
                current = target;
              }
              [array addObject:[NSNumber numberWithInteger: val]];
            }
            NSInteger parent = ((NSInteger)[array count] - 2) / 2;
            NSInteger current = (NSInteger)[array count] - 1;
            while (parent >= 0) {
              if (((NSNumber *)[array objectAtIndex: parent]).integerValue >
                  ((NSNumber *)[array objectAtIndex: current]).integerValue) {
                [array exchangeObjectAtIndex: current withObjectAtIndex: parent];
                current = parent;
                parent = (parent - 1) / 2;
              } else {
                break;
              }
            }
          }
          NSInteger sum = 0;
          for(i=0;i<[array count];i++) {
            sum += ((NSNumber *)[array objectAtIndex: i]).integerValue;
          }
          printf("%ld", sum);
  		  return 0;
}