#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  char i = getchar();
  long long f = 1, res = 0;
  while (i < '0' || i > '9') {
    if (i == '-') f = -1;
    i = getchar();
  }
  while (i >= '0' && i <= '9') {
    res = res * 10 + i - '0';
    i = getchar();
  }
  return f * res;
}
const int N = 50005;
int dp[N];
int n, K;
int a[N], pre[N], pos[N];
int maxn[N << 2], lazy[N << 2];
inline void pushup(int rt) { maxn[rt] = max(maxn[rt << 1], maxn[rt << 1 | 1]); }
inline void pushdown(int rt) {
  if (lazy[rt]) {
    lazy[rt << 1] += lazy[rt];
    lazy[rt << 1 | 1] += lazy[rt];
    maxn[rt << 1] += lazy[rt];
    maxn[rt << 1 | 1] += lazy[rt];
    lazy[rt] = 0;
  }
}
inline void update(int L, int R, int l, int r, int rt) {
  if (L <= l && r <= R) {
    maxn[rt] += 1;
    lazy[rt] += 1;
    return;
  }
  int mid = (l + r) >> 1;
  pushdown(rt);
  if (L <= mid) update(L, R, l, mid, rt << 1);
  if (R > mid) update(L, R, mid + 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 maxn[rt];
  }
  int mid = (l + r) >> 1;
  int res = 0;
  pushdown(rt);
  if (L <= mid) res = max(res, query(L, R, l, mid, rt << 1));
  if (R > mid) res = max(res, query(L, R, mid + 1, r, rt << 1 | 1));
  return res;
}
inline void build(int l, int r, int rt) {
  lazy[rt] = 0;
  if (l == r) {
    maxn[rt] = dp[l - 1];
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, rt << 1);
  build(mid + 1, r, rt << 1 | 1);
  pushup(rt);
}
int main() {
  n = read(), K = read();
  for (int i = 1; i <= n; ++i) {
    a[i] = read();
    pos[i] = pre[a[i]] + 1;
    pre[a[i]] = i;
  }
  memset(pre, -1, sizeof pre);
  for (int i = 1; i <= K; ++i) {
    build(1, n, 1);
    for (int j = 1; j <= n; ++j) {
      update(pos[j], j, 1, n, 1);
      dp[j] = query(1, j, 1, n, 1);
    }
  }
  cout << dp[n] << endl;
}
