#include <bits/stdc++.h>
using namespace std;
int s[200005], lz[200005], p[35005], a[35005], b[35005];
int f[35005][60];
void push_down(int t, int l, int r, int mid) {
  if (lz[t]) {
    s[t << 1] += lz[t];
    lz[t << 1] += lz[t];
    s[t << 1 | 1] += lz[t];
    lz[t << 1 | 1] += lz[t];
    lz[t] = 0;
  }
}
void update(int t, int v, int l, int r, int ll, int rr) {
  if (ll <= l && r <= rr) {
    s[t] += v;
    lz[t] += v;
    return;
  }
  int mid = (l + r) / 2;
  push_down(t, l, r, mid);
  if (mid >= ll) update(t << 1, v, l, mid, ll, rr);
  if (mid < rr) update(t << 1 | 1, v, mid + 1, r, ll, rr);
  s[t] = max(s[t << 1], s[t << 1 | 1]);
}
int query(int t, int l, int r, int ll, int rr) {
  if (ll <= l && r <= rr) {
    return s[t];
  }
  int ret = 0;
  int mid = (l + r) / 2;
  push_down(t, l, r, mid);
  if (mid >= ll) ret = query(t << 1, l, mid, ll, rr);
  if (mid < rr) ret = max(ret, query(t << 1 | 1, mid + 1, r, ll, rr));
  return ret;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; i++) {
    p[i] = b[a[i]];
    b[a[i]] = i;
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= 200005; j++) {
      lz[j] = s[j] = 0;
    }
    for (int j = i - 1; j <= n; j++) update(1, f[j][i - 1], 0, n, j, j);
    f[i][i] = i;
    for (int j = i; j <= n; j++) {
      update(1, 1, 0, n, max(p[j], i - 1), j - 1);
      f[j][i] = query(1, 0, n, i - 1, j - 1);
    }
  }
  printf("%d", f[n][m]);
  return 0;
}
