#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int sum = 0, p = 1;
  char ch = getchar();
  while (!(('0' <= ch && ch <= '9') || ch == '-')) ch = getchar();
  if (ch == '-') p = -1, ch = getchar();
  while ('0' <= ch && ch <= '9') sum = sum * 10 + ch - 48, ch = getchar();
  return sum * p;
}
const int inf = 0x3f3f3f3f;
const int maxn = 5e4 + 20;
int n, k, a[maxn];
int dp[52][maxn];
inline void init() {
  n = read();
  k = read();
  for (int i = (1), _end_ = (n); i <= _end_; i++) a[i] = read();
}
int s[maxn], vis[maxn], tim;
int res;
int ql, qr;
void solve(int l, int r, int L, int R, int t, int op) {
  int mid = (l + r) >> 1;
  int mxid = mid - 1;
  int GL = min(R, mid) + 1, GR = mid;
  while (ql < GL)
    if (!--s[a[ql++]]) res--;
  while (ql > GL)
    if (!s[a[++ql]]++) res++;
  while (qr > GR)
    if (!--s[a[qr--]]) res--;
  while (qr < GR)
    if (!s[a[++qr]]++) res++;
  for (int i = (min(R, mid)), _end_ = (L); i >= _end_; i--) {
    if (!s[a[--ql]]++) ++res;
    if (res + dp[t - 1][i - 1] > dp[t][mid])
      dp[t][mid] = res + dp[t - 1][i - 1], mxid = i;
  }
  if (l == r) return;
  solve(l, mid, L, mxid, t, 1);
  solve(mid + 1, r, mxid, R, t, 2);
}
inline void doing() {
  dp[0][0] = 0;
  for (int i = (1), _end_ = (n); i <= _end_; i++) dp[0][i] = -inf;
  for (int i = (1), _end_ = (k); i <= _end_; i++) {
    memset(dp[i], -63, sizeof(dp[i]));
    res = 0;
    ql = n / 2;
    qr = n / 2 - 1;
    memset(s, 0, sizeof(s));
    solve(i, n, i, n, i, 0);
  }
  printf("%d\n", dp[k][n]);
}
int main() {
  init();
  doing();
  return 0;
}
