#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
inline long long read() {
  long long X = 0, w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
  return w ? -X : X;
}
long long n, k;
long long dp[55][50005];
long long seg[200005];
long long lazy[200005];
long long a[50005];
long long pre[50005];
long long pos[50005];
void build(int pos, int l, int r, int rt) {
  lazy[rt] = 0;
  if (l == r) {
    seg[rt] = dp[pos][l - 1];
    return;
  }
  int mid = (l + r) >> 1;
  build(pos, l, mid, rt << 1);
  build(pos, mid + 1, r, rt << 1 | 1);
  seg[rt] = max(seg[rt << 1 | 1], seg[rt << 1]);
}
void update(int L, int R, int l, int r, int rt) {
  if (L <= l and r <= R) {
    seg[rt]++;
    lazy[rt]++;
    return;
  }
  seg[rt << 1] += lazy[rt];
  seg[rt << 1 | 1] += lazy[rt];
  lazy[rt << 1] += lazy[rt];
  lazy[rt << 1 | 1] += lazy[rt];
  lazy[rt] = 0;
  int mid = (l + r) >> 1;
  if (L <= mid) {
    update(L, R, l, mid, rt << 1);
  }
  if (R > mid) {
    update(L, R, mid + 1, r, rt << 1 | 1);
  }
  seg[rt] = max(seg[rt << 1 | 1], seg[rt << 1]);
}
int query(int L, int R, int l, int r, int rt) {
  if (L <= l and r <= R) {
    return seg[rt];
  }
  seg[rt << 1] += lazy[rt];
  seg[rt << 1 | 1] += lazy[rt];
  lazy[rt << 1] += lazy[rt];
  lazy[rt << 1 | 1] += lazy[rt];
  lazy[rt] = 0;
  int mid = (l + r) >> 1;
  int ans = 0;
  if (L <= mid) {
    ans = max(ans, query(L, R, l, mid, rt << 1));
  }
  if (R > mid) {
    ans = max(ans, query(L, R, mid + 1, r, rt << 1 | 1));
  }
  seg[rt] = max(seg[rt << 1 | 1], seg[rt << 1]);
  return ans;
}
int main() {
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    pre[i] = pos[a[i]] + 1;
    pos[a[i]] = i;
  }
  for (long long i = 1; i <= k; i++) {
    build(i - 1, 1, n, 1);
    for (long long j = 1; j <= n; j++) {
      update(pre[j], j, 1, n, 1);
      dp[i][j] = query(1, j, 1, n, 1);
    }
  }
  cout << dp[k][n];
  return 0;
}
