#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T &res) {
  res = 0;
  T f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    res = res * 10 + c - '0';
    c = getchar();
  }
  res *= f;
}
template <class T>
void out(T x) {
  if (x < 0) {
    x = -x;
    putchar('-');
  }
  if (x >= 10) out(x / 10);
  putchar('0' + x % 10);
}
int N, K, a[100005], cnt[100005];
long long f[22][100005], w = 0;
int nw, p, q;
long long work(int l, int r) {
  while (q < r) w += cnt[a[++q]]++;
  while (p > l) w += cnt[a[--p]]++;
  while (p < l) w -= --cnt[a[p++]];
  while (q > r) w -= --cnt[a[q--]];
  return w;
}
long long Calc(int a, int b) { return f[nw - 1][a] + work(a + 1, b); }
void Solve(int l, int r, int ql, int qr) {
  if (l > r) return;
  int mid = (l + r) >> 1, p = min(qr, mid - 1);
  int k;
  f[nw][mid] = Calc(ql, mid);
  k = ql;
  for (int i = ql + 1; i <= p; ++i) {
    long long x = Calc(i, mid);
    if (x <= f[nw][mid]) {
      f[nw][mid] = x;
      k = i;
    }
  }
  Solve(l, mid - 1, ql, k);
  Solve(mid + 1, r, k, qr);
}
int main() {
  read(N);
  read(K);
  for (int i = 1; i <= N; ++i) {
    read(a[i]);
    f[1][i] = f[1][i - 1] + cnt[a[i]]++;
  }
  for (int i = 2; i <= K; ++i) {
    memset(cnt, 0, sizeof(cnt));
    p = 1;
    q = 0;
    w = 0;
    nw = i;
    Solve(0, N, 0, N);
  }
  out(f[K][N]);
  putchar('\n');
}
