#include <bits/stdc++.h>
using namespace std;
const int maxn = 35000 + 10;
int n, k;
int dp[55][maxn];
int tree[maxn << 2], lazy[maxn << 2];
int pre[maxn], pos[maxn];
inline void push_up(int o) { tree[o] = max(tree[o << 1], tree[o << 1 | 1]); }
inline void push_down(int o) {
  if (lazy[o]) {
    tree[o << 1] += lazy[o];
    tree[o << 1 | 1] += lazy[o];
    lazy[o << 1 | 1] += lazy[o];
    lazy[o << 1] += lazy[o];
    lazy[o] = 0;
  }
}
void update(int l, int r, int L, int R, int o) {
  if (l >= L && r <= R) {
    tree[o] += 1;
    lazy[o] += 1;
    return;
  }
  push_down(o);
  int mid = (l + r) >> 1;
  if (mid >= L) update(l, mid, L, R, o << 1);
  if (mid < R) update(mid + 1, r, L, R, o << 1 | 1);
  push_up(o);
}
int query(int l, int r, int L, int R, int o = 1) {
  if (l >= L && r <= R) return tree[o];
  push_down(o);
  int mid = (l + r) >> 1;
  int ans = 0;
  if (mid >= L) ans = max(ans, query(l, mid, L, R, o << 1));
  if (mid < R) ans = max(ans, query(mid + 1, r, L, R, o << 1 | 1));
  push_up(o);
  return ans;
}
void build(int now, int l, int r, int o) {
  lazy[o] = 0;
  if (l == r) {
    tree[o] = dp[now][l - 1];
    return;
  }
  int mid = (l + r) >> 1;
  build(now, l, mid, o << 1);
  build(now, mid + 1, r, o << 1 | 1);
  push_up(o);
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    pre[i] = pos[x] + 1;
    pos[x] = i;
  }
  for (int i = 1; i <= k; ++i) {
    build(i - 1, 1, n, 1);
    for (int j = 1; j <= n; ++j) {
      update(1, n, pre[j], j, 1);
      dp[i][j] = query(1, n, 1, j, 1);
    }
  }
  printf("%d\n", dp[k][n]);
  return 0;
}
