#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x = 0, F = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') F = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + c - '0';
    c = getchar();
  }
  return x * F;
}
int n, k, a[35000 + 5], p[35000 + 5], pre[35000 + 5];
int dp[50 + 5][35000 + 5];
struct Seg_tree {
  int sum[(35000 << 2) + 5], tag[(35000 << 2) + 5];
  void pushdown(int x) {
    if (tag[x]) {
      tag[x << 1] += tag[x], tag[x << 1 | 1] += tag[x];
      sum[x << 1] += tag[x], sum[x << 1 | 1] += tag[x];
      tag[x] = 0;
    }
  }
  void pushup(int x) { sum[x] = max(sum[x << 1], sum[x << 1 | 1]); }
  void Build(int x, int l, int r, int d) {
    sum[x] = 0, tag[x] = 0;
    if (l == r) {
      sum[x] = dp[d - 1][l - 1], tag[x] = 0;
      return;
    }
    int mid = (l + r) >> 1;
    Build(x << 1, l, mid, d);
    Build(x << 1 | 1, mid + 1, r, d);
    pushup(x);
  }
  void Insert(int x, int l, int r, int L, int R, int v) {
    if (r < L || R < l) return;
    if (L <= l && R >= r) {
      sum[x] += v, tag[x] += v;
      return;
    }
    pushdown(x);
    int mid = (l + r) >> 1;
    Insert(x << 1, l, mid, L, R, v), Insert(x << 1 | 1, mid + 1, r, L, R, v);
    pushup(x);
  }
  int Query(int x, int l, int r, int L, int R) {
    if (r < L || R < l) return 0;
    if (L <= l && R >= r) return sum[x];
    pushdown(x);
    int mid = (l + r) >> 1;
    return max(Query(x << 1, l, mid, L, R),
               Query(x << 1 | 1, mid + 1, r, L, R));
  }
} T;
int main() {
  n = read(), k = read();
  for (int i = 1; i <= n; i++) {
    a[i] = read();
    p[i] = pre[a[i]] + 1;
    pre[a[i]] = i;
  }
  for (int i = 1; i <= k; i++) {
    T.Build(1, 1, n, i);
    for (int j = 1; j <= n; j++) {
      T.Insert(1, 1, n, p[j], j, 1);
      dp[i][j] = T.Query(1, 1, n, 1, j);
    }
  }
  printf("%d", dp[k][n]);
}
