#include <bits/stdc++.h>
using namespace std;
struct Seg {
  int Max, Lazy;
};
Seg A[(35000 + 2) << 2];
int n, k, a[(35000 + 2)], Pre[(35000 + 2)], g[(35000 + 2)],
    f[(50 + 1)][(35000 + 2)];
void init() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  memset(g, 0, sizeof(g));
  for (int i = 1; i <= n; ++i) Pre[i] = g[a[i]], g[a[i]] = i;
  memset(f, 0, sizeof(f));
}
void Update(int rt) { A[rt].Max = max(A[rt << 1].Max, A[rt << 1 | 1].Max); }
void Push(int rt) {
  int Val = A[rt].Lazy;
  A[rt << 1].Max += Val;
  A[rt << 1 | 1].Max += Val;
  A[rt << 1].Lazy += Val;
  A[rt << 1 | 1].Lazy += Val;
  A[rt].Lazy = 0;
}
void Add(int l, int r, int rt, int ll, int rr) {
  int mid = (l + r) >> 1;
  if (l < r) Push(rt);
  if (ll <= l && rr >= r) {
    A[rt].Lazy++;
    A[rt].Max++;
    return;
  }
  if (ll <= mid) Add(l, mid, rt << 1, ll, rr);
  if (rr > mid) Add(mid + 1, r, rt << 1 | 1, ll, rr);
  Update(rt);
}
void Ins(int l, int r, int rt, int Pos, int Val) {
  int mid = (l + r) >> 1;
  if (l < r) Push(rt);
  if (l == r) {
    A[rt].Max = Val;
    A[rt].Lazy = 0;
    return;
  }
  if (Pos <= mid) Ins(l, mid, rt << 1, Pos, Val);
  if (Pos > mid) Ins(mid + 1, r, rt << 1 | 1, Pos, Val);
  Update(rt);
}
int Query(int l, int r, int rt, int ll, int rr) {
  int mid = (l + r) >> 1;
  if (l < r) Push(rt);
  if (l <= ll && r >= rr) return A[rt].Max;
  int M = 0;
  if (ll <= mid) M = Query(l, mid, rt << 1, ll, rr);
  if (rr > mid) M = max(M, Query(mid + 1, r, rt << 1 | 1, ll, rr));
  Update(rt);
  return M;
}
bool p[(35000 + 2)];
void DO_IT() {
  memset(p, 0, sizeof(p));
  memset(f, 0, sizeof(f));
  for (int i = 1; i <= n; ++i) {
    f[1][i] = f[1][i - 1];
    if (!p[a[i]]) f[1][i]++;
    p[a[i]] = 1;
  }
  for (int t = 2; t <= k; ++t) {
    memset(A, 0, sizeof(A));
    for (int i = 1; i <= n; ++i) {
      if (i > 1) Add(1, n, 1, max(Pre[i], 1), i - 1);
      f[t][i] = max(f[t - 1][i], Query(1, n, 1, 1, i - 1));
      Ins(1, n, 1, i, f[t - 1][i]);
    }
  }
}
int main() {
  init();
  DO_IT();
  cout << f[k][n];
  return 0;
}
