#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char ch = getchar();
  int f = 1, x = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
int add[200005], sum[200005], dp[51][50001], pre[50001], pos[50001];
void pushup(int rt) { sum[rt] = max(sum[rt << 1], sum[rt << 1 | 1]); }
void pushdown(int rt, int m) {
  if (add[rt]) {
    add[rt << 1] += add[rt];
    add[rt << 1 | 1] += add[rt];
    sum[rt << 1] += add[rt];
    sum[rt << 1 | 1] += add[rt];
    add[rt] = 0;
  }
}
inline void build(int l, int r, int rt, int pos) {
  add[rt] = 0;
  if (l == r) {
    sum[rt] = dp[pos][l - 1];
    return;
  }
  int m = l + r >> 1;
  build(l, m, rt << 1, pos);
  build(m + 1, r, rt << 1 | 1, pos);
  pushup(rt);
}
inline void update(int L, int R, int c, int l, int r, int rt) {
  if (L <= l && r <= R) {
    add[rt] += c;
    sum[rt] += c;
    return;
  }
  pushdown(rt, r - l + 1);
  int m = l + r >> 1;
  if (L <= m) update(L, R, c, l, m, rt << 1);
  if (m < R) update(L, R, c, m + 1, r, rt << 1 | 1);
  pushup(rt);
}
inline int query(int L, int R, int l, int r, int rt) {
  if (L <= l && r <= R) return sum[rt];
  pushdown(rt, r - l + 1);
  int m = l + r >> 1, ret = 0;
  if (L <= m) ret = query(L, R, l, m, rt << 1);
  if (m < R) ret = max(ret, query(L, R, m + 1, r, rt << 1 | 1));
  return ret;
}
int main() {
  int n = read(), k = read();
  for (int i = 1; i <= n; ++i) {
    int x = read();
    pre[i] = pos[x] + 1;
    pos[x] = i;
  }
  for (int i = 1; i <= k; ++i) {
    memset(sum, 0, sizeof sum);
    build(1, n, 1, i - 1);
    for (int j = 1; j <= n; ++j) {
      update(pre[j], j, 1, 1, n, 1);
      dp[i][j] = query(1, j, 1, n, 1);
    }
  }
  printf("%d\n", dp[k][n]);
  return 0;
}
