#include <bits/stdc++.h>
using namespace std;
int n, k;
int f[50005][65], a[50005], po[50005], cnt, tr[65][200005], la[65][200005];
void pushup(int num, int id) {
  tr[num][id] = max(tr[num][id << 1], tr[num][id << 1 | 1]);
}
void pushdo(int num, int id) {
  if (la[num][id] != 0) {
    la[num][id << 1] += la[num][id];
    la[num][id << 1 | 1] += la[num][id];
    tr[num][id << 1] += la[num][id];
    tr[num][id << 1 | 1] += la[num][id];
    la[num][id] = 0;
  }
}
void upda(int num, int id, int l, int r, int x, int y, int p) {
  if (x <= l && r <= y) {
    tr[num][id] += p;
    la[num][id] += p;
    return;
  }
  pushdo(num, id);
  int m = (l + r) >> 1;
  if (x <= m) upda(num, id << 1, l, m, x, y, p);
  if (y > m) upda(num, id << 1 | 1, m + 1, r, x, y, p);
  pushup(num, id);
}
int query(int num, int id, int l, int r, int x, int y) {
  if (x <= l && r <= y) return tr[num][id];
  pushdo(num, id);
  int m = (l + r) >> 1, ans = 0;
  if (x <= m) ans = max(ans, query(num, id << 1, l, m, x, y));
  if (y > m) ans = max(ans, query(num, id << 1 | 1, m + 1, r, x, y));
  return ans;
}
inline int min(int x, int y) {
  if (x < y) return x;
  return y;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= k; i++) upda(0, 1, 0, n, i, i, -2e9);
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= min(i, k); j++) {
      upda(j, 1, 0, n, po[a[i]], i - 1, 1);
    }
    po[a[i]] = i;
    for (int j = 1; j <= min(i, k); j++) {
      f[i][j] = query(j - 1, 1, 0, n, 0, i - 1);
      upda(j, 1, 0, n, i, i, f[i][j]);
    }
  }
  printf("%d\n", f[n][k]);
  return 0;
}
