#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1100;
int f[MAXN][MAXN], p[MAXN];
int main() {
  int N, K;
  scanf("%d%d", &N, &K);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &p[i]);
  }
  memset(f, 63, sizeof f);
  f[0][0] = 0;
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= i; ++j) {
      f[i][j] = min(f[i - 1][j - 1] + p[i], f[i - 1][j]);
    }
  }
  printf("%d\n", f[N][K]);
  return 0;
}
