#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
const int MAX = 3.5e4 + 10;
int dp[MAX][2];
int freq[MAX], v[MAX], qt, n;
void insert(int p) {
  if (!freq[v[p]]) qt++;
  freq[v[p]]++;
}
void erase(int p) {
  freq[v[p]]--;
  if (!freq[v[p]]) qt--;
}
int query(int l, int r) {
  static int L = 0, R = 0;
  r++;
  while (R < r) insert(R++);
  while (L > l) insert(--L);
  while (L < l) erase(L++);
  while (R > r) erase(--R);
  return qt;
}
void solve(int k, int l = 1, int r = n, int lk = 1, int rk = n) {
  if (l > r) return;
  int m = (l + r) / 2, p = -1, ans = -INF;
  for (int i = min(m, rk); i >= lk; i--) {
    int at = dp[i - 1][~k & 1] + query(i, m);
    if (at > ans) ans = at, p = i;
  }
  dp[m][k & 1] = ans;
  solve(k, l, m - 1, lk, p), solve(k, m + 1, r, p, rk);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> v[i];
  for (int i = 1; i <= k; i++) solve(i);
  cout << dp[n][k & 1] << endl;
  exit(0);
}
