#include <bits/stdc++.h>
using namespace std;
int a[100010];
map<int, int> M;
long long int dp[100010][25];
struct query {
  int S, L, R, BL, BR, D;
};
query make(int s, int l, int r, int bl, int br) {
  query q;
  q.S = s;
  q.L = l;
  q.R = r;
  q.BL = bl;
  q.BR = br;
  return q;
}
vector<query> st[100010];
vector<pair<int, int> > V;
map<int, long long int> cost[100010];
int cnt[100010];
long long int res;
vector<int> F;
void clrs() {
  for (int i = 0; i < F.size(); i++) cost[F[i]].clear();
  F.clear();
}
vector<int> TT;
void add(int x) {
  TT.push_back(x);
  res += cnt[x];
  cnt[x]++;
}
void rem(int x) {
  TT.push_back(x);
  res -= cnt[x] - 1;
  cnt[x]--;
}
void process(int d) {
  V.clear();
  for (int i = 0; i < TT.size(); i++) cnt[TT[i]] = 0;
  TT.clear();
  res = 0;
  for (int i = 0; i < (int)st[d].size(); i++) {
    int l = st[d][i].L;
    int r = st[d][i].R;
    int bl = st[d][i].BL;
    int br = st[d][i].BR;
    int mid = (l + r) / 2;
    for (int i = bl; i <= br; i++) {
      if (i > mid) continue;
      V.push_back(make_pair(i, mid));
    }
  }
  sort(V.begin(), V.end());
  int l = 0, r = 0;
  for (int i = 0; i < V.size(); i++) {
    while (r < V[i].second) {
      r++;
      add(a[r]);
    }
    while (l < V[i].first) {
      if (l != 0 and l <= r) {
        rem(a[l]);
      }
      l++;
    }
    cost[V[i].first][V[i].second] = res;
    F.push_back(V[i].first);
  }
}
void clr() {
  for (int i = 0; i < TT.size(); i++) cnt[TT[i]] = 0;
  TT.clear();
  res = 0;
}
int lp, rp;
void comp(int s, int l, int r, int bl, int br, int d) {
  int mid = (l + r) / 2;
  int opt = bl;
  while (rp < mid) {
    rp++;
    add(a[rp]);
  }
  while (lp < bl) {
    if (lp != 0 and lp <= rp) {
      rem(a[lp]);
    }
    lp++;
  }
  long long int cur = dp[bl][s - 1] + res;
  for (int i = bl; i <= br; i++) {
    if (i > mid) continue;
    while (rp < mid) {
      rp++;
      add(a[rp]);
    }
    while (lp < i) {
      if (lp != 0 and lp <= rp) {
        rem(a[lp]);
      }
      lp++;
    }
    if (dp[i - 1][s - 1] + res <= cur) {
      opt = i;
      cur = dp[i - 1][s - 1] + res;
    }
  }
  dp[mid][s] = cur;
  if (l <= mid - 1) st[d + 1].push_back(make(s, l, mid - 1, bl, opt));
  if (mid + 1 <= r) st[d + 1].push_back(make(s, mid + 1, r, opt, br));
}
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= k; j++) dp[i][j] = 1000000000LL;
  }
  for (int i = 1; i <= n; i++) {
    add(a[i]);
    dp[i][1] = res;
  }
  res = 0;
  clr();
  for (int i = 2; i <= k; i++) {
    for (int j = 0; j < 100010; j++) {
      if (st[j].empty()) break;
      st[j].clear();
    }
    st[0].push_back(make(i, 1, n, 1, n));
    for (int j = 0; j < 100010; j++) {
      if (st[j].empty()) break;
      clr();
      lp = 0;
      rp = 0;
      for (int k = 0; k < st[j].size(); k++) {
        query q = st[j][k];
        comp(i, q.L, q.R, q.BL, q.BR, j);
      }
    }
  }
  cout << dp[n][k] << endl;
}
