#include <bits/stdc++.h>
const int maxn = 5e4 + 10;
const int N = 5e2 + 10;
using namespace std;
long long gcd(long long p, long long q) { return q == 0 ? p : gcd(q, p % q); }
long long qpow(long long p, long long q, long long mo) {
  long long f = 1;
  while (q) {
    if (q & 1) f = f * p % mo;
    p = p * p % mo;
    q >>= 1;
  }
  return f;
}
int n, m, k, t, dp[51][maxn], ma[maxn << 2], tag[maxn << 2], pre[maxn],
    lst[maxn], a[maxn];
void pup(int rt) {
  ma[rt] = max(ma[rt << 1], ma[rt << 1 | 1]);
  tag[rt] = 0;
}
void pdw(int rt) {
  ma[rt << 1] += tag[rt];
  ma[rt << 1 | 1] += tag[rt];
  tag[rt << 1] += tag[rt];
  tag[rt << 1 | 1] += tag[rt];
  tag[rt] = 0;
}
void build(int l, int r, int rt, int dp[]) {
  if (l == r) {
    ma[rt] = dp[l - 1];
    tag[rt] = 0;
    return;
  }
  int mid = l + r >> 1;
  build(l, mid, rt << 1, dp);
  build(mid + 1, r, rt << 1 | 1, dp);
  pup(rt);
}
void upd(int L, int R, int v, int l, int r, int rt) {
  if (L == l && R == r) {
    ma[rt] += v;
    tag[rt] += v;
    return;
  }
  int mid = l + r >> 1;
  if (tag[rt]) pdw(rt);
  if (R <= mid)
    upd(L, R, v, l, mid, rt << 1);
  else if (L > mid)
    upd(L, R, v, mid + 1, r, rt << 1 | 1);
  else
    upd(L, mid, v, l, mid, rt << 1),
        upd(mid + 1, R, v, mid + 1, r, rt << 1 | 1);
  pup(rt);
}
int gao(int L, int R, int l, int r, int rt) {
  if (L == l && R == r) return ma[rt];
  int mid = l + r >> 1;
  if (tag[rt]) pdw(rt);
  if (R <= mid)
    return gao(L, R, l, mid, rt << 1);
  else if (L > mid)
    return gao(L, R, mid + 1, r, rt << 1 | 1);
  else
    return max(gao(L, mid, l, mid, rt << 1),
               gao(mid + 1, R, mid + 1, r, rt << 1 | 1));
}
int main() {
  int i, j;
  scanf("%d%d", &n, &k);
  for (i = 1; i <= (int)n; i++) {
    scanf("%d", &a[i]);
    pre[i] = lst[a[i]];
    lst[a[i]] = i;
  }
  for (i = 1; i <= (int)k; i++) {
    build(1, n, 1, dp[i - 1]);
    for (j = 1; j <= (int)n; j++) {
      upd(pre[j] + 1, j, 1, 1, n, 1);
      dp[i][j] = gao(1, j, 1, n, 1);
    }
  }
  printf("%d\n", dp[k][n]);
  return 0;
}
