#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e4 + 10;
int maxs[maxn * 4], lazy[maxn * 4];
int dp[maxn];
void push_up(int id) { maxs[id] = max(maxs[id << 1], maxs[id << 1 | 1]); }
void build(int id, int l, int r) {
  lazy[id] = 0;
  maxs[id] = 0;
  if (l == r) {
    maxs[id] = dp[l];
    return;
  }
  int mid = (l + r) >> 1;
  build(id << 1, l, mid);
  build(id << 1 | 1, mid + 1, r);
  push_up(id);
}
void push_down(int id) {
  if (lazy[id] == 0) return;
  maxs[id << 1] += lazy[id];
  maxs[id << 1 | 1] += lazy[id];
  lazy[id << 1] += lazy[id];
  lazy[id << 1 | 1] += lazy[id];
  lazy[id] = 0;
}
void update(int id, int l, int r, int x, int y, int val) {
  if (x <= l && y >= r) {
    maxs[id] += val;
    lazy[id] += val;
    return;
  }
  push_down(id);
  int mid = (l + r) >> 1;
  if (x <= mid) update(id << 1, l, mid, x, y, val);
  if (y > mid) update(id << 1 | 1, mid + 1, r, x, y, val);
  push_up(id);
}
int query(int id, int l, int r, int x, int y) {
  if (x <= l && y >= r) return maxs[id];
  push_down(id);
  int ans = 0, mid = (l + r) >> 1;
  if (x <= mid) ans = max(ans, query(id << 1, l, mid, x, y));
  if (y > mid) ans = max(ans, query(id << 1 | 1, mid + 1, r, x, y));
  return ans;
}
int last[maxn];
int a[maxn];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int j = 1; j <= k; j++) {
    memset(last, 0, sizeof(last));
    build(1, 0, n);
    for (int i = 1; i <= n; i++) {
      update(1, 0, n, last[a[i]], i - 1, 1);
      last[a[i]] = i;
      dp[i] = query(1, 0, n, 0, i - 1);
    }
  }
  printf("%d\n", dp[n]);
  return 0;
}
