#include <bits/stdc++.h>
using namespace std;
int n, m, a[35000 * 4], pre[35000 * 4], b[35000 * 4], pos[35000 * 4],
    s[35000 * 4], f[35000 * 4];
void Up(int k) {
  b[k * 2] += b[k];
  b[k * 2 + 1] += b[k];
  s[k * 2] += b[k];
  s[k * 2 + 1] += b[k];
  b[k] = 0;
}
void Insert(int k, int l, int r, int x, int y, int z) {
  if (x <= l && y >= r) {
    s[k] += z;
    b[k] += z;
    return;
  }
  if (b[k]) Up(k);
  if (x <= (l + r) / 2) Insert(k * 2, l, (l + r) / 2, x, y, z);
  if (y > (l + r) / 2) Insert(k * 2 + 1, (l + r) / 2 + 1, r, x, y, z);
  s[k] = max(s[k * 2], s[k * 2 + 1]);
}
int Query(int k, int l, int r, int x, int y) {
  if (x <= l && y >= r) return s[k];
  int res = 0;
  if (b[k]) Up(k);
  if (x <= (l + r) / 2) res = max(res, Query(k * 2, l, (l + r) / 2, x, y));
  if (y > (l + r) / 2)
    res = max(res, Query(k * 2 + 1, (l + r) / 2 + 1, r, x, y));
  return res;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    pre[i] = pos[a[i]];
    pos[a[i]] = i;
  }
  for (int j = 1; j <= m; j++) {
    memset(s, 0, sizeof(s));
    memset(b, 0, sizeof(b));
    for (int i = 1; i <= n; i++) Insert(1, 1, n, i, i, f[i - 1]);
    for (int i = 1; i <= n; i++) {
      Insert(1, 1, n, pre[i] + 1, i, 1);
      f[i] = Query(1, 1, n, 1, i);
    }
  }
  printf("%d\n", f[n]);
  return 0;
}
