#include <bits/stdc++.h>
using namespace std;
inline long long rd() {
  long long x = 0, w = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-') w = -1, c = getchar();
  while (isdigit(c)) x = x * 10 + c - 48, c = getchar();
  return x * w;
}
const int N = 200005;
const long long inf = 1ll * N * N * N;
int n, k, l, r, a[N], s[N];
long long res, f[25][N];
void mov(int tl, int tr) {
  while (l > tl) res += s[a[--l]]++;
  while (r < tr) res += s[a[++r]]++;
  while (l < tl) res -= --s[a[l++]];
  while (r > tr) res -= --s[a[r--]];
}
void sol(int k, int l, int r, int tl, int tr) {
  if (l > r) return;
  int m = l + r >> 1, p = tl;
  f[k][m] = inf;
  for (int i = (tl); i <= (min(m, tr)); ++i) {
    mov(i, m);
    long long w = f[k - 1][i - 1] + res;
    if (f[k][m] > w) f[k][m] = w, p = i;
  }
  sol(k, l, m - 1, tl, p);
  sol(k, m + 1, r, p, tr);
}
int main() {
  n = rd();
  k = rd();
  for (int i = (1); i <= (n); ++i) a[i] = rd();
  for (int i = (1); i <= (n); ++i) res += s[a[i]]++, f[1][i] = res;
  l = 1;
  r = 0;
  res = 0;
  memset(s, 0, sizeof(s));
  for (int i = (2); i <= (k); ++i) sol(i, 1, n, 1, n);
  printf("%lld\n", f[k][n]);
  return 0;
}
