#include <bits/stdc++.h>
using namespace std;
template <typename T>
T read1() {
  T t = 0;
  char k;
  bool vis = 0;
  do (k = getchar()) == '-' && (vis = 1);
  while ('0' > k || k > '9');
  while ('0' <= k && k <= '9')
    t = (t << 3) + (t << 1) + (k ^ '0'), k = getchar();
  return vis ? -t : t;
}
int s, k, a[100005], h[100005], L = 1, R;
long long f[21][100005], t;
void Turn(int l, int r) {
  while (R < r) t += h[a[++R]]++;
  while (L > l) t += h[a[--L]]++;
  while (R > r) t -= --h[a[R--]];
  while (L < l) t -= --h[a[L++]];
}
void solve(int x, int l, int r, int ql, int qr) {
  if (l > r) return;
  int mid = l + r >> 1, v = 0;
  long long ans = 9e18;
  for (int i = ql; i <= min(qr, mid - 1); ++i) {
    Turn(i + 1, mid);
    if (t + f[x - 1][i] < ans) ans = t + f[x - 1][i], v = i;
  }
  f[x][mid] = ans;
  solve(x, l, mid - 1, ql, v);
  solve(x, mid + 1, r, v, qr);
}
int main() {
  s = read1<long long>(), k = read1<long long>();
  memset(f, 0x3f, sizeof(f));
  for (int i = 1; i <= s; ++i) a[i] = read1<long long>();
  f[0][0] = 0;
  for (int i = 1; i <= k; ++i) solve(i, 1, s, 0, s - 1);
  printf("%lld", f[k][s]);
  return 0;
}
