#include <bits/stdc++.h>
using namespace std;
const int M = 1001001001;
vector<int> p;
int dp[1000][1000];
int n, k;
int buy(int i, int cnt) {
  if (dp[i][cnt] >= 0) {
    return dp[i][cnt];
  }
  int total = 0;
  if (cnt == k) {
    total = 0;
  } else if (i == n) {
    total = M;
  } else {
    total += min(buy(i + 1, cnt), buy(i + 1, cnt + 1) + p[i]);
  }
  dp[i][cnt] = total;
  return total;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < (n); i++) {
    int x;
    cin >> x;
    p.push_back(x);
  }
  memset(dp, -1, sizeof(dp));
  cout << buy(0, 0) << endl;
  return 0;
}
