program main;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
ss,raz,f,t,j,tt,i,sum:integer;
s2: array [1..1000] of string;
t1,max,s1,s3: array [1..100] of integer;
begin
assignfile(input,'A.in');
assignfile (output,'A.out');
reset (input);
rewrite (output);
t:=0;
For i:=1 to 2 do
readln (input, s2[i]);
for i:=1 to 2 do
begin
t:=t+1;
for j:= 0 to length(s2[i]) do
if (s2[i,j]<>' ') then
begin
s1[t]:=strtoint(inttostr(s1[t])+s2[i,j]);
end
else
t:=t+1;
end;
raz:=s1[1]-s1[2];
max[1]:=s1[3];
for i:= 1 to raz do
begin
for j:= 3 to s1[1]+2 do
for f:= 1 to raz do
if not(j=t1[f]) then
if s1[j]>=max[i] then
begin
max [i]:=s1[j];
tt:=tt+1 ;
t1[tt]:=j;
end;
sum:=sum+max[i];
end;
writeln (output,inttostr(sum));
close (output);
  { TODO -oUser -cConsole Main : Insert code here }
end.
 