#include <bits/stdc++.h>
using namespace std;
const int MAXN = 35005;
const int MAXK = 55;
int n, m;
int a[MAXN];
int dp[MAXK][MAXN];
int tran[MAXK][MAXN];
int last[MAXN];
int val[MAXN];
int updated[MAXN];
void get_last() {
  int rec[MAXN];
  memset(rec, 0, sizeof(int) * n + 5);
  for (int i = 1; i <= n; i++) {
    last[i] = rec[a[i]];
    rec[a[i]] = i;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  get_last();
  for (int i = 1; i <= n; i++) {
    for (int k = min(i, m); k >= 1; k--) {
      int l = max(tran[k][i - 1], k - 1);
      int r = (tran[k + 1][i] == 0 ? i - 1 : tran[k + 1][i]);
      for (int j = l; j <= r; j++) {
        if (updated[j + 1] != i) {
          updated[j + 1] = i;
          val[j + 1] += (last[i] < j + 1);
        }
        if (dp[k][i] < dp[k - 1][j] + val[j + 1]) {
          dp[k][i] = dp[k - 1][j] + val[j + 1];
          tran[k][i] = j;
        }
      }
    }
  }
  printf("%d", dp[m][n]);
  return 0;
}
