#include <bits/stdc++.h>
using namespace std;
const long long int MAXN = 35005;
long long int dp[55][MAXN];
long long int d[4 * MAXN], Tree[4 * MAXN];
long long int N, K;
long long int A[MAXN];
long long int P[MAXN];
void build(long long int node, long long int l, long long int r,
           long long int k) {
  if (l == r) {
    Tree[node] = dp[k][l];
  } else {
    long long int mid = (l + r) / 2;
    build(2 * node, l, mid, k);
    build(2 * node + 1, mid + 1, r, k);
  }
}
void lazyUpdate(long long int node, long long int len) {
  if (len <= 0) return;
  if (!d[node]) return;
  Tree[node] += d[node];
  if (len > 1) {
    d[2 * node] += d[node];
    d[2 * node + 1] += d[node];
  }
  d[node] = 0;
}
void update(long long int node, long long int start, long long int end,
            long long int L, long long int R) {
  lazyUpdate(node, end - start + 1);
  if (start > end || end < L || start > R || L > R) return;
  if (L <= start && end <= R) {
    d[node]++;
    lazyUpdate(node, end - start + 1);
    return;
  }
  long long int mid = (start + end) / 2;
  update(2 * node, start, mid, L, R);
  update(2 * node + 1, mid + 1, end, L, R);
  Tree[node] = max(Tree[2 * node], Tree[2 * node + 1]);
}
long long int get(long long int node, long long int start, long long int end,
                  long long int L, long long int R) {
  lazyUpdate(node, end - start + 1);
  if (start > end || end < L || start > R || L > R) return 0;
  if (L <= start && end <= R) {
    return Tree[node];
  }
  long long int mid = (start + end) / 2;
  long long int left = get(2 * node, start, mid, L, R);
  long long int right = get(2 * node + 1, mid + 1, end, L, R);
  return max(left, right);
}
void solve(long long int k) {
  fill_n(Tree, 4 * N, 0);
  fill_n(d, 4 * N, 0);
  build(1, 1, N, k - 1);
  for (long long int i = 1; i <= N; i++) {
    if (P[i] <= i - 1 && i != 1) {
      update(1, 1, N, P[i], i - 1);
    }
    dp[k][i] = max(dp[k - 1][i], get(1, 1, N, 1, i - 1));
  }
}
map<long long int, long long int> last;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> N >> K;
  for (long long int i = 1; i <= N; i++) {
    cin >> A[i];
  }
  for (long long int i = 1; i <= N; i++) {
    P[i] = -1;
    if (last.find(A[i]) != last.end()) {
      P[i] = last[A[i]];
    } else {
      P[i] = 1;
    }
    last[A[i]] = i;
  }
  set<long long int> st;
  for (long long int i = 1; i <= N; i++) {
    st.insert(A[i]);
    dp[1][i] = st.size();
  }
  for (long long int i = 2; i <= K; i++) {
    solve(i);
  }
  cout << dp[K][N] << endl;
}
