#include <bits/stdc++.h>
using namespace std;
const int maxn = 35010;
int n, k, a[maxn], l1[maxn], last[maxn], mx[4 * maxn], la[4 * maxn], dp[maxn];
void shift(int l, int r, int node) {
  mx[node] += la[node];
  if (l == r) {
    la[node] = 0;
    return;
  }
  la[2 * node] += la[node];
  la[(2 * node) + 1] += la[node];
  la[node] = 0;
}
void add(int x, int y, int va, int l = 0, int r = n, int node = 1) {
  shift(l, r, node);
  if (l > y || r < x) return;
  if (l >= x && r <= y) {
    la[node] += va;
    shift(l, r, node);
    return;
  }
  int mid = (r + l) / 2;
  add(x, y, va, l, mid, 2 * node);
  add(x, y, va, mid + 1, r, (2 * node) + 1);
  mx[node] = max(mx[2 * node], mx[(2 * node) + 1]);
}
void up(int x, int va, int l = 0, int r = n, int node = 1) {
  shift(l, r, node);
  if (l > x || r < x) return;
  if (l >= x && r <= x) {
    mx[node] = va;
    return;
  }
  int mid = (r + l) / 2;
  up(x, va, l, mid, 2 * node);
  up(x, va, mid + 1, r, (2 * node) + 1);
  mx[node] = max(mx[2 * node], mx[(2 * node) + 1]);
}
int ask(int x, int y, int l = 0, int r = n, int node = 1) {
  shift(l, r, node);
  if (l > y || r < x) return 0;
  if (l >= x && r <= y) return mx[node];
  int mid = (r + l) / 2;
  return max(ask(x, y, l, mid, 2 * node),
             ask(x, y, mid + 1, r, (2 * node) + 1));
}
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    l1[i] = last[a[i]];
    last[a[i]] = i;
  }
  for (int j = 1; j <= k; j++) {
    for (int i = j; i <= n; i++) {
      add(j - 1, i - 1, 1);
      add(j - 1, l1[i] - 1, -1);
      dp[i] = ask(j - 1, i - 1);
    }
    for (int i = j; i <= n; i++) up(i, dp[i]);
  }
  cout << ask(n, n);
  return 0;
}
