#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-4;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n, k, a[35010];
int dp[2][35010], cnt, pre[35010];
struct SegTree {
  struct node {
    int mx, add;
  } t[35010 << 2];
  void down(int rt) {
    if (t[rt].add) {
      t[rt << 1].mx += t[rt].add, t[rt << 1 | 1].mx += t[rt].add;
      t[rt << 1].add += t[rt].add, t[rt << 1 | 1].add += t[rt].add;
      t[rt].add = 0;
    }
  }
  void up(int rt) { t[rt].mx = max(t[rt << 1].mx, t[rt << 1 | 1].mx); }
  void build(int l, int r, int rt, int v[]) {
    t[rt].add = 0;
    if (l == r) {
      t[rt].mx = v[l];
      return;
    }
    int m = (l + r) >> 1;
    build(l, m, rt << 1, v), build(m + 1, r, rt << 1 | 1, v);
    up(rt);
  }
  void add(int l, int r, int rt, int L, int R, int x) {
    if (L <= l && r <= R) {
      t[rt].mx += x;
      t[rt].add += x;
      return;
    }
    down(rt);
    int m = (l + r) >> 1;
    if (L <= m) add(l, m, rt << 1, L, R, x);
    if (R > m) add(m + 1, r, rt << 1 | 1, L, R, x);
    up(rt);
  }
  int querymx(int l, int r, int rt, int L, int R) {
    if (L <= l && r <= R) return t[rt].mx;
    down(rt);
    int m = (l + r) >> 1, ans = -0x3f3f3f3f;
    if (L <= m) ans = max(ans, querymx(l, m, rt << 1, L, R));
    if (R > m) ans = max(ans, querymx(m + 1, r, rt << 1 | 1, L, R));
    return ans;
  }
} seg;
int main() {
  n = read(), k = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (!pre[a[i]])
      dp[cnt][i] = dp[cnt][i - 1] + 1;
    else
      dp[cnt][i] = dp[cnt][i - 1];
    pre[a[i]] = i;
  }
  for (int i = 2; i <= k; i++) {
    cnt ^= 1;
    seg.build(1, n, 1, dp[cnt ^ 1]);
    for (int j = 1; j <= n; j++) pre[a[j]] = 0;
    for (int j = 1; j < i; j++) dp[cnt][j] = 0;
    for (int j = i; j <= n; j++) {
      int l = max(1, pre[a[j]]), r = j - 1;
      seg.add(1, n, 1, l, r, 1);
      dp[cnt][j] = seg.querymx(1, n, 1, i - 1, r);
      pre[a[j]] = j;
    }
  }
  printf("%d\n", dp[cnt][n]);
  return 0;
}
