Program Divide;
Uses Math;

Const
      MaxN=10000;

Var f: Text;
    n, k: LongInt;  //
    s: Array [0..MaxN] of LongInt;
    t: Array [1..MaxN] of LongInt;
    i, m: LongInt;
    j, l, r: LongInt;

Begin
  {Input}
//  Assign(f, 'row.in'); Reset(f);
  Readln(n, k);
  s[0]:= 0;
  For i:= 1 To n Do Begin
    Read(r);
    s[i]:= s[i-1]+r;
    t[i]:= s[i];
  End;
//  Close(f);
  For m:= 2 To k Do Begin
    For i:= n DownTo m Do Begin
      l:= m-1;
      r:= i-1;
      While r>l+1 Do Begin
        j:= (l+r) div 2;
        If t[j]<s[i]-s[j] Then Begin
          l:= j;
        End
        Else Begin
          r:= j;
        End;
      End;
      t[i]:= min ( s[i]-s[l], t[r]);
    End;
  End;

  {Output}
 // Assign(f, 'row.out'); Rewrite(f);
  Writeln(t[n]);
//  Close(f);
End.
