#include <bits/stdc++.h>
using namespace std;
inline int RD() {
  int res;
  char cr;
  while ((cr = getchar()) < '0' || cr > '9')
    ;
  res = cr - '0';
  while ((cr = getchar()) >= '0' && cr <= '9') res = res * 10 + cr - '0';
  return res;
}
int tmp[305005];
int las[305005], pre[305005];
int dp[305005];
int ans;
int mx[305005 * 8], pv[305005 * 8];
void update(int p) {
  mx[p] =
      ((mx[p << 1]) > (mx[(p << 1) | 1]) ? (mx[p << 1]) : (mx[(p << 1) | 1]));
}
void pushdown(int p) {
  if (pv[p]) {
    pv[p << 1] += pv[p];
    pv[(p << 1) | 1] += pv[p];
    mx[p << 1] += pv[p];
    mx[(p << 1) | 1] += pv[p];
    pv[p] = 0;
  }
}
void setTree(int p, int l, int r) {
  pv[p] = 0;
  if (l == r) {
    mx[p] = dp[l];
    return;
  }
  int mid = (l + r) >> 1;
  setTree(p << 1, l, mid);
  setTree((p << 1) | 1, mid + 1, r);
  update(p);
}
void modify(int p, int l, int r, int gl, int gr, int v) {
  if (gr <= 0) return;
  if (gl <= 0) gl = 1;
  if (l == gl && r == gr) {
    mx[p] += v;
    pv[p] += v;
    return;
  }
  pushdown(p);
  int mid = (l + r) >> 1;
  if (gr <= mid)
    modify(p << 1, l, mid, gl, gr, v);
  else if (gl > mid)
    modify((p << 1) | 1, mid + 1, r, gl, gr, v);
  else
    modify(p << 1, l, mid, gl, mid, v),
        modify((p << 1) | 1, mid + 1, r, mid + 1, gr, v);
  update(p);
}
int query(int p, int l, int r, int gl, int gr) {
  if (gr <= 0) return 0;
  if (gl <= 0) gl = 1;
  if (l == gl && r == gr) return mx[p];
  pushdown(p);
  int mid = (l + r) >> 1;
  int res = 0;
  if (gr <= mid)
    res = query(p << 1, l, mid, gl, gr);
  else if (gl > mid)
    res = query((p << 1) | 1, mid + 1, r, gl, gr);
  else {
    res = query(p << 1, l, mid, gl, mid);
    int r2 = query((p << 1) | 1, mid + 1, r, mid + 1, gr);
    res = ((res) > (r2) ? (res) : (r2));
  }
  update(p);
  return res;
}
int main() {
  int n, K;
  n = RD();
  K = RD();
  for (int i = 1; i <= n; i++) {
    int val = RD();
    pre[i] = las[val];
    las[val] = i;
    dp[i] = dp[i - 1] + (pre[i] == 0);
  }
  setTree(1, 1, n);
  while (--K) {
    for (int i = 1; i <= n; i++) tmp[i] = 0;
    for (int i = 2; i <= n; i++) {
      modify(1, 1, n, pre[i], i - 1, 1);
      tmp[i] = query(1, 1, n, 1, i - 1);
    }
    for (int i = 1; i <= n; i++) dp[i] = tmp[i];
    setTree(1, 1, n);
  }
  printf("%d\n", dp[n]);
}
