#include <bits/stdc++.h>
using namespace std;
struct Node {
  Node *l, *r;
  int v, delta, lc, rc;
  Node() {
    l = r = NULL;
    v = delta = lc = rc = 0;
  }
  Node(int _v) {
    v = _v;
    l = r = NULL;
    delta = lc = rc = 0;
  }
  void pushdown() {
    if (l) {
      l->delta += delta;
      l->v += delta;
    }
    if (r) {
      r->delta += delta;
      r->v += delta;
    }
    delta = 0;
  }
  void update() {
    pushdown();
    v = max((l ? l->v : 0), (r ? r->v : 0));
  }
} * root[55];
inline Node *build(int l, int r) {
  Node *x = new Node(), *ls = NULL, *rs = NULL;
  x->lc = l;
  x->rc = r;
  if (l == r) return x;
  int mid = (l + r) >> 1;
  if (l <= mid) {
    ls = build(l, mid);
    x->l = ls;
  }
  if (r > mid) {
    rs = build(mid + 1, r);
    x->r = rs;
  }
  return x;
}
inline void modify(Node *s, int L, int R, int val) {
  if (L <= s->lc && s->rc <= R) {
    s->delta += val;
    s->v += val;
    return;
  }
  s->pushdown();
  int mid = (s->lc + s->rc) >> 1;
  if (L <= mid) {
    modify(s->l, L, R, val);
  }
  if (R > mid) {
    modify(s->r, L, R, val);
  }
  s->update();
}
inline int query(Node *s, int L, int R) {
  s->pushdown();
  if (L <= s->lc && s->rc <= R) {
    return s->v;
  }
  int ans = 0, mid = (s->lc + s->rc) >> 1;
  if (L <= mid) {
    ans = max(ans, query(s->l, L, R));
  }
  if (R > mid) {
    ans = max(ans, query(s->r, L, R));
  }
  return ans;
}
int f[55][35100], n, k, a[35100], last[35100], head[35100];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    last[i] = head[a[i]];
    head[a[i]] = i;
  }
  root[0] = build(0, n);
  for (int i = 1; i <= k; i++) {
    root[i] = build(0, n);
    for (int j = i; j <= n; j++) {
      modify(root[i - 1], last[j], j - 1, 1);
      f[i][j] = query(root[i - 1], i - 1, j - 1);
      modify(root[i], j, j, f[i][j]);
    }
  }
  printf("%d\n", f[k][n]);
}
