#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5;
int l = 0;
int r = 0;
int res = 0;
int f[maxn + 11][55];
int a[maxn + 11];
int cnt[maxn + 11];
void add(int x) {
  if (!cnt[a[x]]) res++;
  cnt[a[x]]++;
}
void del(int x) {
  cnt[a[x]]--;
  if (!cnt[a[x]]) res--;
}
int calc(int L, int R) {
  while (r < R) add(++r);
  while (r > R) del(r--);
  while (l > L) add(--l);
  while (l < L) del(l++);
  return res;
}
void solve(int k, int l, int r, int al, int ar) {
  int mid = (l + r) >> 1;
  if (l > r || al > ar) return;
  int ind = 0;
  for (int i = al; i <= min(ar, mid - 1); i++) {
    if (f[i][k - 1] + calc(i + 1, mid) > f[mid][k]) {
      f[mid][k] = f[i][k - 1] + calc(i + 1, mid);
      ind = i;
    }
  }
  solve(k, l, mid - 1, al, ind);
  solve(k, mid + 1, r, ind, ar);
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= k; i++) solve(i, 1, n, 0, n);
  cout << f[n][k] << endl;
}
