#include <bits/stdc++.h>
using namespace std;
const int N = 36000;
int f[60][N], a[N], pre[N];
struct Node {
  int l, r, v, add;
} tr[N * 4];
void pushup(int u) { tr[u].v = max(tr[u << 1].v, tr[u << 1 | 1].v); }
void pushdown(int u) {
  int l = u << 1, r = u << 1 | 1;
  tr[l].add += tr[u].add, tr[l].v += tr[u].add;
  tr[r].add += tr[u].add, tr[r].v += tr[u].add;
  tr[u].add = 0;
}
void modify(int u, int l, int r, int v) {
  if (tr[u].l >= l && tr[u].r <= r) {
    tr[u].v += v, tr[u].add += v;
    return;
  }
  pushdown(u);
  int mid = (tr[u].l + tr[u].r) >> 1;
  if (l <= mid) modify(u << 1, l, r, v);
  if (r > mid) modify(u << 1 | 1, l, r, v);
  pushup(u);
}
int query(int u, int l, int r) {
  if (tr[u].l >= l && tr[u].r <= r) {
    return tr[u].v;
  }
  pushdown(u);
  int mid = (tr[u].l + tr[u].r) >> 1, ans = 0;
  if (l <= mid) ans = query(u << 1, l, r);
  if (r > mid) ans = max(ans, query(u << 1 | 1, l, r));
  return ans;
}
void build(int u, int l, int r, int k) {
  tr[u].l = l, tr[u].r = r, tr[u].add = 0;
  if (l == r) {
    tr[u].v = f[k][l];
    return;
  }
  int mid = (l + r) >> 1;
  build(u << 1, l, mid, k);
  build(u << 1 | 1, mid + 1, r, k);
  pushup(u);
}
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= k; i++) {
    memset(tr, 0, sizeof(tr));
    memset(pre, 0, sizeof(pre));
    build(1, 0, n, i - 1);
    for (int p = 1; p <= n; p++) {
      modify(1, pre[a[p]], p - 1, 1);
      pre[a[p]] = p;
      f[i][p] = query(1, 0, p - 1);
    }
  }
  cout << f[k][n] << endl;
}
