#include <bits/stdc++.h>
inline char nc() {
  static char buf[1000000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
template <class T>
inline void read(T &x) {
  static char c;
  for (c = getchar(); !('0' <= c && c <= '9'); c = getchar())
    ;
  for (x = 0; ('0' <= c && c <= '9'); c = getchar()) x = x * 10 + c - 48;
}
template <class T>
void write(T x) {
  if (x < 10) {
    putchar('0' + x);
    return;
  }
  write(x / 10);
  putchar('0' + x % 10);
}
template <class T>
inline void writeln(T x) {
  if (x < 0) putchar('-'), x *= -1;
  write(x);
  putchar('\n');
}
template <class T>
inline void writel(T x) {
  if (x < 0) putchar('-'), x *= -1;
  write(x);
  putchar(' ');
}
using namespace std;
int mx[40017 << 2], lazy[40017 << 2], dp[52][40017];
void up(int no) { mx[no] = max(mx[no << 1], mx[no << 1 | 1]); }
void down(int no) {
  mx[no << 1] += lazy[no];
  mx[no << 1 | 1] += lazy[no];
  lazy[no << 1] += lazy[no];
  lazy[no << 1 | 1] += lazy[no];
  lazy[no] = 0;
}
void build(int no, int L, int R, int lst) {
  if (L == R) {
    mx[no] = dp[lst][L - 1];
    return;
  }
  build(no << 1, L, ((L + R) >> 1), lst);
  build(no << 1 | 1, ((L + R) >> 1) + 1, R, lst);
  up(no);
}
void add(int no, int L, int R, int l, int r, int dla) {
  if (l <= L && R <= r) {
    mx[no] += dla;
    lazy[no] += dla;
    return;
  }
  down(no);
  if (l <= ((L + R) >> 1)) add(no << 1, L, ((L + R) >> 1), l, r, dla);
  if (r > ((L + R) >> 1)) add(no << 1 | 1, ((L + R) >> 1) + 1, R, l, r, dla);
  up(no);
}
int ask(int no, int L, int R, int l, int r) {
  if (l <= L && R <= r) {
    return mx[no];
  }
  down(no);
  int now = 0;
  if (l <= ((L + R) >> 1))
    now = max(now, ask(no << 1, L, ((L + R) >> 1), l, r));
  if (r > ((L + R) >> 1))
    now = max(now, ask(no << 1 | 1, ((L + R) >> 1) + 1, R, l, r));
  return now;
}
int n, k, pos[40017], pre[40017], a[40017];
signed main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    pre[i] = pos[a[i]];
    pos[a[i]] = i;
  }
  for (int t = 1; t <= k; t++) {
    build(1, 1, n, t - 1);
    memset(lazy, 0, sizeof lazy);
    for (int i = 1; i <= n; i++) {
      add(1, 1, n, pre[i] + 1, i, 1);
      dp[t][i] = ask(1, 1, n, 1, i);
    }
  }
  writeln(dp[k][n]);
  return 0;
}
