#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long infinity = 1000000000000000000;
const int inf = 1e9 + 5;
bool do_debug = false;
const int maxn = 35005, maxk = 51;
int n, k;
int a[maxn], cnt[maxn] = {0};
int pdp[maxn] = {0}, cdp[maxn] = {0};
int L = 1, R = 0, gain = 0;
void g(int l, int r) {
  while (R < r) {
    R++;
    if (!cnt[a[R]]) {
      gain++;
    }
    cnt[a[R]]++;
  }
  while (L < l) {
    cnt[a[L]]--;
    if (!cnt[a[L]]) {
      gain--;
    }
    L++;
  }
  while (L > l) {
    L--;
    if (!cnt[a[L]]) {
      gain++;
    }
    cnt[a[L]]++;
  }
  while (R > r) {
    cnt[a[R]]--;
    if (!cnt[a[R]]) {
      gain--;
    }
    R--;
  }
}
void f(int l, int r, int o_l, int o_r) {
  if (l > r) {
    return;
  }
  int mid = ((r - l) >> 1) + l;
  int ans = -1;
  int o = 0;
  for (int i = o_l; i < min(mid, o_r) + 1; i++) {
    g(i, mid);
    int t = pdp[i - 1] + gain;
    if (t > ans) {
      ans = t;
      o = i;
    }
  }
  cdp[mid] = ans;
  f(l, mid - 1, o_l, o);
  f(mid + 1, r, o, o_r);
}
void solve() {
  cin >> n >> k;
  for (int i = 1; i < n + 1; i++) cin >> a[i];
  for (int i = 1; i < n + 1; i++) {
    g(1, i);
    pdp[i] = gain;
  }
  for (int K = 2; K < k + 1; K++) {
    f(1, n, 1, n);
    for (int i = 1; i < n + 1; i++) pdp[i] = cdp[i];
  }
  cout << pdp[n] << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int q = 1;
  while (q-- > 0) {
    solve();
  }
  return 0;
}
