#include <bits/stdc++.h>
using namespace std;
unsigned int min(unsigned int A, unsigned int B) {
  if (A < B) {
    return A;
  } else {
    return B;
  }
}
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> P;
  P.push_back(0);
  for (int i = 0; i < N; i++) {
    int p;
    cin >> p;
    P.push_back(p);
  }
  int dp[N + 1][K + 1];
  dp[0][0] = 0;
  for (int i = 1; i <= K; i++) {
    dp[0][i] = 0x0FFFFFFF;
  }
  for (int i = 1; i <= N; i++) {
    dp[i][0] = 0;
    for (int k = 1; k <= K; k++) {
      dp[i][k] = min(dp[i - 1][k - 1] + P[i], dp[i - 1][k]);
    }
  }
  for (int i = 0; i <= N; i++) {
    for (int k = 0; k <= K; k++) {
      clog << dp[i][k] << " ";
    }
    clog << endl;
  }
  cout << dp[N][K] << endl;
  return 0;
}
