#include <bits/stdc++.h>
using namespace std;
int n, k;
int A[35002], cnt[35001];
int dp[51][35001];
int val = 0;
int curL = 1, curR = 0;
void slide(int L, int R) {
  while (curR < R) {
    curR++;
    cnt[A[curR]]++;
    if (cnt[A[curR]] == 1) ++val;
  }
  while (curL > L) {
    curL--;
    cnt[A[curL]]++;
    if (cnt[A[curL]] == 1) ++val;
  }
  while (curR > R) {
    cnt[A[curR]]--;
    if (cnt[A[curR]] == 0) --val;
    curR--;
  }
  while (curL < L) {
    cnt[A[curL]]--;
    if (cnt[A[curL]] == 0) --val;
    curL++;
  }
}
void calc(int box, int l, int r, int optl, int optr) {
  if (l > r) return;
  int m = (l + r) / 2;
  optl = max(0, optl);
  dp[box][m] = -1e9;
  int best = -1;
  for (int i = optl; i < min(optr + 1, m); ++i) {
    slide(i + 1, m);
    if (val + dp[box - 1][i] > dp[box][m])
      dp[box][m] = val + dp[box - 1][i], best = i;
  }
  calc(box, l, m - 1, optl, best);
  calc(box, m + 1, r, best, optr);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> A[i];
  for (int i = 1; i <= n; ++i) slide(1, i), dp[1][i] = val;
  for (int i = 2; i <= k; ++i) calc(i, 1, n, 1, n);
  cout << dp[k][n] << endl;
  return 0;
}
