#include <bits/stdc++.h>
using namespace std;
const int maxn = 350000 + 100;
int data[maxn];
int dp[2][maxn];
int hash1[maxn];
int tree[maxn * 4];
int flag[maxn * 4];
int prev_pos[maxn];
void inc(int root, int l, int r, int a, int b, int delta) {
  if (a == l && b == r) {
    flag[root] += delta;
    tree[root] += delta;
    return;
  }
  const int lc = root << 1, rc = lc + 1, mid = l + r >> 1;
  if (flag[root] != 0) {
    const int t = flag[root];
    flag[lc] += t, tree[lc] += t, flag[rc] += t, tree[rc] += t, flag[root] = 0;
  }
  if (b <= mid)
    inc(lc, l, mid, a, b, delta);
  else if (a > mid)
    inc(rc, mid + 1, r, a, b, delta);
  else {
    inc(lc, l, mid, a, mid, delta);
    inc(rc, mid + 1, r, mid + 1, b, delta);
  }
  tree[root] = max(tree[lc], tree[rc]);
}
int query(int root, int l, int r, int a, int b) {
  if (l == a && r == b) {
    return tree[root];
  }
  const int lc = root << 1, rc = lc + 1, mid = l + r >> 1;
  if (flag[root] != 0) {
    const int t = flag[root];
    flag[lc] += t, tree[lc] += t, flag[rc] += t, tree[rc] += t, flag[root] = 0;
  }
  if (b <= mid) return query(lc, l, mid, a, b);
  if (a > mid) return query(rc, mid + 1, r, a, b);
  const int u = query(lc, l, mid, a, mid);
  const int v = query(rc, mid + 1, r, mid + 1, b);
  return max(u, v);
}
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; ++i) scanf("%d", data + i);
  int* from = dp[0];
  int* to = dp[1];
  for (int x = 1; x <= k; ++x) {
    if (x == 1) {
      int v = 0;
      for (int i = 1; i <= n; ++i) {
        int orz = hash1[data[i]];
        if (orz == 0) {
          ++v;
        }
        to[i] = v;
        prev_pos[i] = orz;
        hash1[data[i]] = i;
      }
    } else {
      memset(tree, 0, sizeof tree);
      memset(flag, 0, sizeof flag);
      for (int i = x; i <= n; ++i) {
        const int me = from[i - 1];
        const int pos = prev_pos[i];
        inc(1, 1, n, i - 1, i - 1, me);
        inc(1, 1, n, max(x - 1, pos), i - 1, 1);
        to[i] = query(1, 1, n, x - 1, i - 1);
      }
    }
    swap(from, to);
  }
  printf("%d\n", from[n]);
  return 0;
}
