#include <bits/stdc++.h>
using namespace std;
int n, k;
const int N = 35090;
int dp[N][55], la[N], tree[N * 4], vis[N], laz[N * 4], a[N];
void plaz(int ind, int l) {
  tree[ind] += laz[ind];
  if (l > 1) {
    laz[ind * 2 + 1] += laz[ind];
    laz[ind * 2 + 2] += laz[ind];
  }
  laz[ind] = 0;
}
void up(int ind, int st, int end, int l, int r, int x) {
  plaz(ind, end - st + 1);
  if (l > end || r < st) return;
  if (l <= st && end <= r) {
    laz[ind] = x;
    plaz(ind, end - st + 1);
    return;
  }
  int m = (st + end) / 2;
  up(ind * 2 + 1, st, m, l, r, x);
  up(ind * 2 + 2, m + 1, end, l, r, x);
  tree[ind] = max(tree[ind * 2 + 1], tree[ind * 2 + 2]);
}
int get(int ind, int st, int end, int l, int r) {
  plaz(ind, end - st + 1);
  if (l > end || r < st) return 0;
  if (l <= st && end <= r) return tree[ind];
  int m = (st + end) / 2;
  return max(get(ind * 2 + 1, st, m, l, r), get(ind * 2 + 2, m + 1, end, l, r));
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    dp[i][1] += dp[i - 1][1];
    if (!vis[a[i]]) dp[i][1]++;
    vis[a[i]] = 1;
  }
  for (int i = 2; i <= k; i++) {
    for (int j = 0; j <= 4 * n; j++) {
      laz[j] = 0;
      tree[j] = 0;
    }
    for (int j = 1; j < n + 1; j++) up(0, 1, n, j, j, dp[j][i - 1]);
    for (int j = 0; j < n + 1; j++) la[j] = 0;
    for (int j = 1; j < n + 1; j++) {
      up(0, 1, n, la[a[j]], j - 1, 1);
      la[a[j]] = j;
      dp[j][i] = get(0, 1, n, 1, j - 1);
    }
  }
  cout << dp[n][k];
}
