#include <bits/stdc++.h>
using namespace std;
const int max_N = 3e4 + 5e3 + 10;
const int max_K = 55;
int dp[max_K][max_N];
int seg[max_N << 2], lz[max_N << 2];
int last_occ[max_N], prev_occ[max_N];
int inp[max_N];
void propagate(int v, int L, int R);
void update(int v, int L, int R, int rl, int rr, int x);
int query(int v, int L, int R, int rl, int rr);
void build(int v, int L, int R, int *arr);
int main() {
  ios_base::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  for (int i = 1; i <= N; ++i) {
    cin >> inp[i];
  }
  for (int i = 1; i <= N; ++i) {
    last_occ[i] = prev_occ[inp[i]];
    prev_occ[inp[i]] = i;
  }
  for (int d = 1; d <= K; ++d) {
    build(1, 0, N, dp[d - 1]);
    for (int i = 1; i <= N; ++i) {
      update(1, 0, N, last_occ[i], i - 1, 1);
      dp[d][i] = query(1, 0, N, 0, i - 1);
    }
  }
  cout << dp[K][N] << endl;
}
void update(int v, int L, int R, int rl, int rr, int x) {
  propagate(v, L, R);
  if (rl > R || rr < L) {
    return;
  } else if (rl <= L && R <= rr) {
    lz[v] += x;
    propagate(v, L, R);
  } else {
    int mid = (L + R) >> 1;
    update(v * 2, L, mid, rl, rr, x);
    update(v * 2 + 1, mid + 1, R, rl, rr, x);
    seg[v] = max(seg[2 * v], seg[2 * v + 1]);
  }
}
void propagate(int v, int L, int R) {
  seg[v] += lz[v];
  if (L < R) {
    lz[v * 2] += lz[v];
    lz[v * 2 + 1] += lz[v];
  }
  lz[v] = 0;
}
int query(int v, int L, int R, int rl, int rr) {
  propagate(v, L, R);
  if (rl <= L && R <= rr) {
    return seg[v];
  } else if (rl > R || rr < L) {
    return 0;
  } else {
    int mid = (L + R) >> 1;
    return max(query(2 * v, L, mid, rl, rr),
               query(2 * v + 1, mid + 1, R, rl, rr));
  }
}
void build(int v, int L, int R, int *arr) {
  if (L == R) {
    seg[v] = arr[L];
  } else {
    int mid = (L + R) >> 1;
    build(2 * v, L, mid, arr);
    build(2 * v + 1, mid + 1, R, arr);
    seg[v] = max(seg[2 * v + 1], seg[2 * v]);
  }
  lz[v] = 0;
}
