#include <bits/stdc++.h>
using namespace std;
const int Inf = 1e9;
int read() {
  int s = 0, m = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') m = 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
  return m ? -s : s;
}
int n, K;
int v[35050], last[35050], Ans;
struct Segment_Tree {
  int val[35050 << 2], tag[35050 << 2];
  void Puttag(int now, int xx) { val[now] += xx, tag[now] += xx; }
  void Pushdown(int now) {
    if (!tag[now]) return;
    Puttag(now << 1, tag[now]), Puttag(now << 1 | 1, tag[now]);
    tag[now] = 0;
    return;
  }
  void Modify(int now, int L, int R, int le, int ri, int xx) {
    if (L == le && R == ri) {
      Puttag(now, xx);
      return;
    }
    Pushdown(now);
    int mid = (L + R) >> 1;
    if (ri <= mid) Modify(now << 1, L, mid, le, ri, xx);
    if (le > mid) Modify(now << 1 | 1, mid + 1, R, le, ri, xx);
    if (le <= mid && ri > mid)
      Modify(now << 1, L, mid, le, mid, xx),
          Modify(now << 1 | 1, mid + 1, R, mid + 1, ri, xx);
    val[now] = max(val[now << 1], val[now << 1 | 1]);
  }
  int Query(int now, int L, int R, int le, int ri) {
    if (L == le && R == ri) return val[now];
    Pushdown(now);
    int mid = (L + R) >> 1;
    if (ri <= mid) return Query(now << 1, L, mid, le, ri);
    if (le > mid) return Query(now << 1 | 1, mid + 1, R, le, ri);
    if (le <= mid && ri > mid)
      return max(Query(now << 1, L, mid, le, mid),
                 Query(now << 1 | 1, mid + 1, R, mid + 1, ri));
    return 0;
  }
} ljl[55];
int main() {
  n = read(), K = read();
  int ret = 0;
  for (int i = 1; i <= n; ++i) v[i] = read();
  for (int i = 1; i <= n; ++i) {
    ljl[0].Modify(1, 1, n, last[v[i]] + 1, i, 1);
    for (int k = 1; k <= min(K, i); ++k) {
      ljl[k].Modify(1, 1, n, last[v[i]] + 1, i, 1);
      ret = ljl[k - 1].Query(1, 1, n, k, i);
      if (i == n) Ans = max(Ans, ret);
      if (i < n) ljl[k].Modify(1, 1, n, i + 1, i + 1, ret);
    }
    last[v[i]] = i;
  }
  printf("%d\n", Ans);
  return 0;
}
