#include <bits/stdc++.h>
using namespace std;
const int MAXN = 35000;
int last[MAXN + 1], last_pos[MAXN + 1], a[MAXN + 1], dp[MAXN + 1][55];
int t[4 * MAXN + 1], color[4 * MAXN + 1], n;
void push(int v, int l, int r) {
  if (color[v]) {
    color[v * 2] += color[v];
    color[v * 2 + 1] += color[v];
    int m = (l + r) / 2;
    t[v * 2] += color[v];
    t[v * 2 + 1] += color[v];
    color[v] = 0;
  }
}
void upd(int pos, int val, int v, int l, int r) {
  if (l == r) {
    t[v] = val;
  } else {
    push(v, l, r);
    int m = (l + r) / 2;
    if (pos <= m)
      upd(pos, val, v * 2, l, m);
    else
      upd(pos, val, v * 2 + 1, m + 1, r);
    t[v] = max(t[v * 2], t[v * 2 + 1]);
  }
}
void upd(int l, int r, int val, int tv, int tl, int tr) {
  if (l > r)
    return;
  else if (l == tl && r == tr) {
    t[tv] += val;
    color[tv] += val;
  } else {
    push(tv, l, r);
    int tm = (tl + tr) / 2;
    upd(l, min(tm, r), val, tv * 2, tl, tm);
    upd(max(tm + 1, l), r, val, tv * 2 + 1, tm + 1, tr);
    t[tv] = max(t[tv * 2], t[tv * 2 + 1]);
  }
}
int get(int l, int r, int tv = 1, int tl = 1, int tr = n) {
  if (l > r)
    return 0;
  else if (l == tl && r == tr)
    return t[tv];
  else {
    push(tv, l, r);
    int tm = (tl + tr) / 2;
    int res1 = get(l, min(tm, r), tv * 2, tl, tm);
    int res2 = get(max(tm + 1, l), r, tv * 2 + 1, tm + 1, tr);
    return max(res1, res2);
  }
}
int main() {
  int K;
  cin >> n >> K;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (!last[a[i]])
      last_pos[i] = 1;
    else
      last_pos[i] = last[a[i]] + 1;
    last[a[i]] = i;
  }
  for (int k = 1; k <= K; k++) {
    for (int i = 1; i <= n; i++) upd(i, dp[i - 1][k - 1], 1, 1, n);
    for (int i = 1; i <= n; i++) {
      upd(last_pos[i], i, 1, 1, 1, n);
      dp[i][k] = get(1, i);
    }
  }
  cout << dp[n][K] << "\n";
  return 0;
}
