#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0;
  char zf = 1;
  char ch = getchar();
  while (ch != '-' && !isdigit(ch)) ch = getchar();
  if (ch == '-') zf = -1, ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * zf;
}
void write(long long y) {
  if (y < 0) putchar('-'), y = -y;
  if (y > 9) write(y / 10);
  putchar(y % 10 + 48);
}
void writeln(const long long y) {
  write(y);
  putchar('\n');
}
int i, j, k, m, n, x, y, z, cnt;
int v[35010], la[35010], pl[35010], g[55][35010], f[35010];
struct segment {
  int L, R, tag, Max;
} a[35010 * 8];
void build(int id, int x, int L, int R) {
  a[x].L = L;
  a[x].R = R;
  a[x].Max = g[id][L];
  a[x].tag = 0;
  if (L == R) return;
  const int mid = L + R >> 1;
  build(id, x << 1, L, mid);
  build(id, x << 1 | 1, mid + 1, R);
  a[x].Max = max(a[x << 1].Max, a[x << 1 | 1].Max);
}
void change(int x, int L, int R, int val) {
  if (a[x].L > R || a[x].R < L) return;
  if (a[x].L >= L && a[x].R <= R) {
    a[x].tag += val;
    a[x].Max += val;
    return;
  }
  change(x << 1, L, R, val);
  change(x << 1 | 1, L, R, val);
  a[x].Max = max(a[x << 1].Max, a[x << 1 | 1].Max) + a[x].tag;
}
int query(int x, int L, int R) {
  if (a[x].L > R || a[x].R < L) return 0;
  if (a[x].L >= L && a[x].R <= R) return a[x].Max;
  return max(query(x << 1, L, R), query(x << 1 | 1, L, R)) + a[x].tag;
}
int main() {
  n = read();
  m = read();
  for (register int i = 1; i <= n; i++) v[i] = read();
  for (register int i = 1; i <= n; i++) {
    la[i] = pl[v[i]];
    g[1][i] = g[1][i - 1];
    if (!la[i]) g[1][i]++;
    pl[v[i]] = i;
  }
  for (register int i = 2; i <= m; i++) {
    build(i - 1, 1, 1, n);
    for (register int j = 1; j <= n; j++) {
      change(1, la[j], j - 1, 1);
      g[i][j] = query(1, 1, j - 1);
    }
  }
  cout << g[m][n];
  return 0;
}
