#include <bits/stdc++.h>
using namespace std;
using ll = int;
const ll maxn = 3e4 + 5e3 + 5, inf = 1e18, mod = 998244353;
ll n, k, a[maxn], num, dp[55][maxn], lazy[55][maxn * 4];
pair<ll, ll> seg[55][maxn * 4];
vector<ll> v[maxn];
void shift(ll j, ll v, ll s, ll e) {
  if (lazy[j][v] == 0) return;
  ll mid = (e + s) / 2, lc = v + v, rc = lc + 1;
  ll x = lazy[j][v];
  lazy[j][v] = 0;
  seg[j][lc].first += x;
  seg[j][rc].first += x;
  lazy[j][lc] += x;
  lazy[j][rc] += x;
}
pair<ll, ll> get(ll j, ll l, ll r, ll v = 1, ll s = 0, ll e = n) {
  if (s >= r || l >= e) return {-1, 0};
  if (s >= l && e <= r) return seg[j][v];
  shift(j, v, s, e);
  ll mid = (e + s) / 2, lc = v + v, rc = lc + 1;
  return max(get(j, l, r, lc, s, mid), get(j, l, r, rc, mid, e));
}
void add(ll l, ll r, ll j, ll x = 1, ll v = 1, ll s = 0, ll e = n) {
  if (e - s == 1) seg[j][v].second = s;
  if (s >= r || l >= e) return;
  if (s >= l && e <= r) {
    seg[j][v].first += x;
    lazy[j][v] += x;
    return;
  }
  shift(j, v, s, e);
  ll mid = (e + s) / 2, lc = v + v, rc = lc + 1;
  add(l, r, j, x, lc, s, mid);
  add(l, r, j, x, rc, mid, e);
  seg[j][v] = max(seg[j][lc], seg[j][rc]);
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    for (ll j = 0; j <= k; j++) {
      if (v[a[i]].empty())
        add(0, i + 1, j);
      else
        add(v[a[i]].back() + 1, i + 1, j);
      if (j == 0) continue;
      if (j > i + 1)
        dp[j][i] = -maxn;
      else {
        pair<ll, ll> p = get(j - 1, 0, i + 1);
        dp[j][i] = p.first;
      }
      dp[1][0] = 1;
      if (i < n - 1) add(i + 1, i + 2, j, dp[j][i]);
    }
    v[a[i]].push_back(i);
  }
  cout << dp[k][n - 1];
}
