#include <bits/stdc++.h>
using namespace std;
int avl, ara[35004], lst[35004], seg[40 * 35004], lft[40 * 35004],
    rght[40 * 35004], version[35004], suf[35004];
int update(int n, int s, int e, int indx, int val) {
  if (s == indx && e == indx) {
    seg[++avl] = seg[n] + val;
    return avl;
  }
  if (s > indx || e < indx) return n;
  int mid = (s + e) >> 1;
  int x = ++avl;
  lft[x] = update(lft[n], s, mid, indx, val);
  rght[x] = update(rght[n], mid + 1, e, indx, val);
  seg[x] = seg[lft[x]] + seg[rght[x]];
  return x;
}
int query(int n, int s, int e, int l, int r) {
  if (s >= l && e <= r) return seg[n];
  if (s > r || e < l) return 0;
  int mid = (s + e) >> 1;
  return query(lft[n], s, mid, l, r) + query(rght[n], mid + 1, e, l, r);
}
int mem[52][35004];
void dp(int n, int rem, int l, int r, int p1, int p2) {
  if (l > r) return;
  int mid = (l + r) >> 1;
  mem[rem][mid] = 0;
  int ind = p1, c = 0;
  if (p2 < mid) c = query(version[mid], 1, n, p2 + 1, mid);
  for (int i = min(mid, p2); i >= p1; i--) {
    if (suf[i] > mid) c++;
    int x = mem[rem - 1][i - 1] + c;
    if (x >= mem[rem][mid]) mem[rem][mid] = x, ind = i;
  }
  dp(n, rem, l, mid - 1, p1, ind);
  dp(n, rem, mid + 1, r, ind, p2);
  return;
}
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &ara[i]);
    mem[1][i] = mem[1][i - 1];
    version[i] = update(version[i - 1], 1, n, i, 1);
    if (lst[ara[i]])
      version[i] = update(version[i], 1, n, lst[ara[i]], -1);
    else
      mem[1][i]++;
    lst[ara[i]] = i;
  }
  for (int i = 1; i <= n; i++) lst[i] = n + 1;
  for (int i = n; i >= 1; i--) suf[i] = lst[ara[i]], lst[ara[i]] = i;
  for (int i = 2; i <= k; i++) dp(n, i, 1, n, 1, n);
  printf("%d\n", mem[k][n]);
  return 0;
}
