#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1 << 16;
const int MAX_K = 50;
int N, K, A[MAX_N], value[MAX_N][2], best[MAX_N * 2], lazy[MAX_N * 2],
    last[MAX_N];
void propagate(int p, int L, int R) {
  if (lazy[p]) {
    best[p] += lazy[p];
    if (R - L > 1) {
      lazy[p * 2] += lazy[p];
      lazy[p * 2 + 1] += lazy[p];
    }
    lazy[p] = 0;
  }
}
int query(int i, int j, int p = 1, int L = 0, int R = MAX_N) {
  propagate(p, L, R);
  if (j <= L || R <= i) return 0;
  if (i <= L && R <= j) {
    return best[p];
  }
  int M = (L + R) / 2;
  return max(query(i, j, p * 2, L, M), query(i, j, p * 2 + 1, M, R));
}
void inc(int i, int j, int p = 1, int L = 0, int R = MAX_N) {
  propagate(p, L, R);
  if (j <= L || R <= i) return;
  if (i <= L && R <= j) {
    lazy[p] = 1;
    propagate(p, L, R);
    return;
  }
  int M = (L + R) / 2;
  inc(i, j, p * 2, L, M);
  inc(i, j, p * 2 + 1, M, R);
  best[p] = max(best[p * 2], best[p * 2 + 1]);
}
int main() {
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A[i]--;
  }
  for (int k = 0; k < K; k++) {
    if (k > 0) {
      best[MAX_N] = 0;
      for (int i = 1; i < N; i++) {
        best[MAX_N + i] = value[i - 1][(k - 1) & 1];
      }
      for (int i = MAX_N - 1; i; i--) {
        best[i] = max(best[i * 2], best[i * 2 + 1]);
      }
      for (int i = MAX_N * 2 - 1; i; i--) {
        lazy[i] = 0;
      }
      for (int i = 0; i < N; i++) {
        last[i] = 0;
      }
    }
    for (int i = 0; i < N; i++) {
      inc(last[A[i]], i + 1);
      last[A[i]] = i + 1;
      value[i][k & 1] = query(0, i + 1);
    }
  }
  cout << value[N - 1][(K - 1) & 1] << endl;
}
