#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 10, K = 55;
int n, k;
int a[N];
int dp[K][N];
int pre[N];
vector<int> ps[N];
struct Node {
  int lz, mx;
} tr[N << 2];
void pushup(int p, int l, int r) {
  tr[p].mx = max(tr[(p << 1)].mx, tr[(p << 1 | 1)].mx);
  tr[p].lz = 0;
}
void pushdown(int p, int l, int r) {
  if (tr[p].lz != 0) {
    tr[(p << 1)].lz += tr[p].lz;
    tr[(p << 1)].mx += tr[p].lz;
    tr[(p << 1 | 1)].lz += tr[p].lz;
    tr[(p << 1 | 1)].mx += tr[p].lz;
    tr[p].lz = 0;
  }
}
void build(int p, int l, int r, int x) {
  if (l == r) {
    tr[p].lz = 0;
    tr[p].mx = dp[x][l];
    return;
  }
  build((p << 1), l, ((l + r) >> 1), x);
  build((p << 1 | 1), ((l + r) >> 1) + 1, r, x);
  pushup(p, l, r);
}
void update(int p, int l, int r, int ll, int rr, int v) {
  if (ll > rr) return;
  if (ll > r || rr < l) return;
  if (ll <= l && rr >= r) {
    tr[p].lz += v;
    tr[p].mx += v;
    return;
  }
  pushdown(p, l, r);
  update((p << 1), l, ((l + r) >> 1), ll, rr, v);
  update((p << 1 | 1), ((l + r) >> 1) + 1, r, ll, rr, v);
  pushup(p, l, r);
}
int query(int p, int l, int r, int ll, int rr) {
  if (ll > r || rr < l) return 0;
  if (ll <= r && rr >= r) {
    return tr[p].mx;
  }
  pushdown(p, l, r);
  return max(query((p << 1), l, ((l + r) >> 1), ll, rr),
             query((p << 1 | 1), ((l + r) >> 1) + 1, r, ll, rr));
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
  }
  for (int i = 1; i <= n; ++i) {
    if (ps[a[i]].empty()) {
      pre[i] = 0;
    } else {
      pre[i] = ps[a[i]].back();
    }
    ps[a[i]].push_back(i);
  }
  for (int i = 1; i <= k; ++i) {
    build(1, 0, n, i - 1);
    for (int j = 1; j <= n; ++j) {
      update(1, 0, n, pre[j], j - 1, 1);
      dp[i][j] = query(1, 0, n, 0, j - 1);
    }
  }
  printf("%d\n", dp[k][n]);
  return 0;
}
