#include <bits/stdc++.h>
using namespace std;
const int inf = (1 << 30) - 1;
const long long linf = (1ll << 62) - 1;
const int N = 35001;
int n, k;
int a[N];
int dp[N];
int rmq[N * 4 + 100], add[N * 4 + 100];
void make_rmq(int i, int l, int r) {
  add[i] = 0;
  if (l == r) {
    return void(rmq[i] = dp[l]);
  }
  make_rmq(i * 2, l, (l + r) / 2);
  make_rmq(i * 2 + 1, (l + r) / 2 + 1, r);
  rmq[i] = max(rmq[i * 2] + add[i * 2], rmq[i * 2 + 1] + add[i * 2 + 1]);
}
int getMax(int i, int ll, int rr, int l, int r) {
  if (ll > r || rr < l) {
    return -inf;
  }
  if (l <= ll && rr <= r) {
    return rmq[i] + add[i];
  }
  return max(getMax(i * 2, ll, (ll + rr) / 2, l, r),
             getMax(i * 2 + 1, (ll + rr) / 2 + 1, rr, l, r)) +
         add[i];
}
void update(int i, int ll, int rr, int l, int r, int v) {
  if (ll > r || rr < l) {
    return;
  }
  if (l <= ll && rr <= r) {
    return void(add[i] += v);
  }
  update(i * 2, ll, (ll + rr) / 2, l, r, v);
  update(i * 2 + 1, (ll + rr) / 2 + 1, rr, l, r, v);
  rmq[i] = max(rmq[i * 2] + add[i * 2], rmq[i * 2 + 1] + add[i * 2 + 1]);
}
int huev[N];
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]), a[i]--;
  }
  fill_n(dp, n + 1, -inf);
  dp[0] = 0;
  for (int i = 0; i < k; i++) {
    make_rmq(1, 0, n - 1);
    fill_n(huev, n, -1);
    for (int j = 0; j < n; j++) {
      update(1, 0, n - 1, 0, huev[a[j]], -1);
      update(1, 0, n - 1, 0, j, 1);
      dp[j + 1] = getMax(1, 0, n - 1, 0, j);
      huev[a[j]] = j;
    }
  }
  cout << dp[n] << endl;
  return 0;
}
