#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int rand(int x, int y) {
  ++y;
  return (rng() % (y - x)) + x;
}
int n, k, A[300006], dp[35006][56];
vector<pair<int, int> > v;
struct node {
  int second, e, m;
  int v = 0;
  node *l, *r;
  node(int _s, int _e, bool prog) {
    second = _s, e = _e, m = (second + e) / 2;
    v = 0;
    if (second != e && prog) {
      l = new node(second, m, 1);
      r = new node(m + 1, e, 1);
    } else
      l = NULL, r = NULL;
  }
  node *update(int x, int nv) {
    node *tmp = new node(second, e, 0);
    if (second == e) {
      assert(v == 0);
      tmp->v = v + nv;
      return tmp;
    }
    if (x > m) {
      tmp->l = l;
      assert(r != NULL);
      tmp->r = r->update(x, nv);
    } else {
      assert(l != NULL);
      tmp->l = l->update(x, nv);
      tmp->r = r;
    }
    tmp->v = tmp->l->v + tmp->r->v;
    return tmp;
  }
  int rmq(int x, int y) {
    if (second == x && e == y) return v;
    if (x > m)
      return r->rmq(x, y);
    else if (y <= m)
      return l->rmq(x, y);
    else
      return l->rmq(x, m) + r->rmq(m + 1, y);
  }
} * seg[35006];
int ubdd(pair<int, int> x) {
  int st = -1, en = v.size(), mid = 0;
  while (en - st > 1) {
    mid = (st + en) >> 1;
    if (x.first > v[mid].first)
      en = mid;
    else
      st = mid;
  }
  return en + 1;
}
unordered_map<int, int> mp[35006];
int RMQ(int x, int y) {
  if (mp[y].count(x)) return mp[y][x];
  auto itr = ubdd(pair<int, int>(y + 1, -(long long)1e18)) - 1;
  return mp[y][x] = (itr > 0 ? seg[itr]->rmq(x, y) : 0);
  set<int> second;
  for (int i = x; i < y + 1; i++) second.insert(A[i]);
  return second.size();
}
void dnc(int st, int en, int x, int y, int k) {
  if (st > en) return;
  int opt_pos = x;
  int mid = (st + en) / 2;
  for (int i = min(y, mid); i >= x; i--) {
    if (dp[mid][k] < dp[i - 1][k - 1] + RMQ(i, mid)) {
      opt_pos = i;
      dp[mid][k] = dp[i - 1][k - 1] + RMQ(i, mid);
    }
  }
  if (st < mid) dnc(st, mid - 1, x, opt_pos, k);
  if (mid < en) dnc(mid + 1, en, opt_pos, y, k);
}
vector<int> val[35006];
void solve() {
  for (int i = 1; i < n + 1; i++) {
    assert(A[i] <= 35000);
    val[A[i]].push_back(i);
  }
  for (int i = 1; i < n + 1; i++) {
    val[A[i]].push_back(n + 1);
  }
  for (int i = 1; i < n + 1; i++)
    v.push_back(pair<int, int>(
        *upper_bound((val[A[i]]).begin(), (val[A[i]]).end(), i), i));
  sort((v).begin(), (v).end(), greater<pair<int, int> >());
  seg[0] = new node(1, n + 1, 1);
  for (int i = 0; i < v.size(); i++) {
    seg[i + 1] = seg[i]->update(v[i].second, 1);
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i < n + 1; i++) cin >> A[i];
  solve();
  unordered_set<int> second;
  for (int i = 1; i < n + 1; i++) {
    second.insert(A[i]);
    dp[i][1] = second.size();
  }
  for (int i = 2; i < k + 1; i++) {
    dnc(1, n, 1, n, i);
  }
  cout << dp[n][k] << "\n";
}
