#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int MAX = 35000 + 10;
const int MINN = 0;
const int MAXN = 35000 + 10;
int freq[MAX];
long long dp[MAX][2];
int v[MAX], n;
int L, R, ct;
void insert(int p) {
  int o = v[p];
  freq[o]++;
  ct += (freq[o] == 1);
}
void erase(int p) {
  int o = v[p];
  ct -= (freq[o] == 1);
  freq[o]--;
}
long long query(int ql, int qr) {
  while (R < qr) insert(++R);
  while (L > ql) insert(--L);
  while (L < ql) erase(L++);
  while (R > qr) erase(R--);
  return ct;
}
void solve(int li, int ri, int k, int l, int r) {
  if (li > ri) return;
  int mi = (li + ri) / 2;
  int m_ans = l;
  long long ans = -1;
  for (int j = max(l, mi); j <= r; j++) {
    long long tmp = query(mi, j) + dp[j + 1][(k - 1) % 2];
    if (tmp > ans) {
      ans = tmp;
      m_ans = j;
    }
  }
  dp[mi][k % 2] = ans;
  solve(li, mi - 1, k, l, m_ans);
  solve(mi + 1, ri, k, m_ans, r);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> v[i];
  ct = 0;
  memset(freq, 0, sizeof freq);
  L = 0, R = 0;
  insert(0);
  for (int i = 1; i <= k; i++) solve(0, n - 1, i, 0, n - 1);
  cout << dp[0][k % 2] << '\n';
  exit(0);
}
