#include <bits/stdc++.h>
using namespace std;
const int maxn = 35000 + 10;
long long num[maxn * 4], laz[maxn * 4];
int pre[maxn], a[maxn], last[maxn];
int n, k;
long long dp[55][maxn];
void build(int rt, int l, int r, int x) {
  laz[rt] = 0;
  num[rt] = 0;
  if (l == r) {
    num[rt] = dp[x][l - 1];
    return;
  }
  int mid = (l + r) / 2;
  build(rt * 2, l, mid, x);
  build(rt * 2 + 1, mid + 1, r, x);
  num[rt] = max(num[rt * 2], num[rt * 2 + 1]);
}
void pushdown(int rt) {
  if (laz[rt]) {
    num[rt * 2] += laz[rt];
    num[rt * 2 + 1] += laz[rt];
    laz[rt * 2] += laz[rt];
    laz[rt * 2 + 1] += laz[rt];
    laz[rt] = 0;
  }
  return;
}
void update(int l, int r, int L, int R, int rt, int c) {
  if (l <= L && r >= R) {
    num[rt] += c;
    laz[rt] += c;
    return;
  }
  pushdown(rt);
  int mid = (L + R) / 2;
  if (l <= mid) update(l, r, L, mid, rt * 2, c);
  if (r > mid) update(l, r, mid + 1, R, rt * 2 + 1, c);
  num[rt] = max(num[rt * 2], num[rt * 2 + 1]);
}
long long query(int l, int r, int L, int R, int rt) {
  if (l <= L && r >= R) {
    return num[rt];
  }
  pushdown(rt);
  int mid = (L + R) / 2;
  long long ans = 0;
  if (l <= mid) ans = max(ans, query(l, r, L, mid, rt * 2));
  if (r > mid) ans = max(ans, query(l, r, mid + 1, R, rt * 2 + 1));
  return ans;
}
int main() {
  while (~scanf("%d%d", &n, &k)) {
    memset(pre, 0, sizeof(pre));
    memset(last, 0, sizeof(last));
    memset(dp, 0, sizeof(dp));
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      last[i] = pre[a[i]], pre[a[i]] = i;
    }
    for (int i = 1; i <= k; i++) {
      build(1, 1, n, i - 1);
      for (int j = 1; j <= n; j++) {
        update(last[j] + 1, j, 1, n, 1, 1);
        dp[i][j] = query(1, j, 1, n, 1);
      }
    }
    printf("%I64d\n", dp[k][n]);
  }
  return 0;
}
