#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e4 + 7;
int n, k;
int ans;
int a[maxn];
int lasts[maxn];
int tr[55][maxn << 2];
int lazy[55][maxn << 2];
void pushdown(int x, int num) {
  if (lazy[x][num] == 0) return;
  lazy[x][num << 1] += lazy[x][num];
  lazy[x][num << 1 | 1] += lazy[x][num];
  tr[x][num << 1] += lazy[x][num];
  tr[x][num << 1 | 1] += lazy[x][num];
  lazy[x][num] = 0;
  return;
}
void pushup(int x, int num) {
  tr[x][num] = max(tr[x][num << 1], tr[x][num << 1 | 1]);
}
void build(int x, int l, int r, int num) {
  lazy[x][num] = 0;
  if (l == r) {
    tr[x][num] = 0;
    return;
  }
  int mid = (l + r) >> 1;
  build(x, l, mid, num << 1);
  build(x, mid + 1, r, num << 1 | 1);
  pushup(x, num);
}
void modify(int x, int l, int r, int num, int le, int ri, int tmp, int op) {
  if (ri < l || r < le) return;
  if (le <= l && r <= ri) {
    if (op == 1) {
      lazy[x][num] += tmp;
      tr[x][num]++;
      return;
    } else {
      tr[x][num] = tmp;
      return;
    }
  }
  int mid = (l + r) >> 1;
  pushdown(x, num);
  if (le <= mid) modify(x, l, mid, num << 1, le, ri, tmp, op);
  if (mid < ri) modify(x, mid + 1, r, num << 1 | 1, le, ri, tmp, op);
  pushup(x, num);
}
int quriy(int x, int l, int r, int num, int le, int ri) {
  if (ri < l || r < le) return 0;
  if (le <= l && r <= ri) return tr[x][num];
  int mid = (l + r) >> 1;
  int ans = 0;
  pushdown(x, num);
  if (le <= mid) ans = max(ans, quriy(x, l, mid, num << 1, le, ri));
  if (mid < ri) ans = max(ans, quriy(x, mid + 1, r, num << 1 | 1, le, ri));
  pushup(x, num);
  return ans;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  build(0, 1, n + 1, 1);
  for (int i = 1; i <= k; i++) {
    build(i, 1, n + 1, 1);
    memset(lasts, 0, sizeof(lasts));
    for (int j = 1; j <= n; j++) {
      modify(i - 1, 1, n + 1, 1, lasts[a[j]] + 1, j, 1, 1);
      int res = quriy(i - 1, 1, n + 1, 1, 1, j);
      ans = max(res, ans);
      modify(i, 1, n + 1, 1, j + 1, j + 1, res, 2);
      lasts[a[j]] = j;
    }
  }
  printf("%d\n", ans);
  return 0;
}
