#include <bits/stdc++.h>
const int N = 35001;
int last[N], pre[N], dp[N];
int main() {
  int n, m;
  while (scanf("%d%d", &n, &m) == 2) {
    memset(last, 0, sizeof(*last) * (n + 1));
    for (int i = 1, a; i <= n; ++i) {
      scanf("%d", &a);
      pre[i] = last[a];
      last[a] = i;
    }
    dp[0] = 0;
    for (int i = 1; i <= n; ++i) {
      dp[i] = dp[i - 1] + !pre[i];
    }
    for (int k = 2; k <= m; ++k) {
      std::map<int, int> c;
      c[0] = n + 1;
      int last_dp = dp[k - 1];
      for (int i = k; i <= n; ++i) {
        int now = 0;
        while (now + c.rbegin()->second <= last_dp) {
          now += c.rbegin()->second;
          c.erase(c.rbegin()->first);
        }
        c.rbegin()->second += now - last_dp;
        c[i] = last_dp + 1;
        auto iterator = c.upper_bound(pre[i]);
        iterator--;
        iterator->second--;
        if (iterator->second == 0) {
          c.erase(iterator->first);
        }
        last_dp = dp[i];
        dp[i] = (n + 1) - c.begin()->second;
      }
    }
    printf("%d\n", dp[n]);
  }
}
