#include <bits/stdc++.h>
using namespace std;
const int N = 35010, K = 55;
int a[N], dp[K][N];
int seg[4 * N], lazy[4 * N];
void build_tree(int idx, int l, int r, int v[]) {
  if (l != r) {
    int mid = (l + r) / 2;
    build_tree(2 * idx + 1, l, mid, v);
    build_tree(2 * idx + 2, mid + 1, r, v);
  }
  seg[idx] = v[l], lazy[idx] = 0;
}
void upd(int idx, int l, int r) {
  if (lazy[idx]) {
    if (l != r) {
      lazy[2 * idx + 1] += lazy[idx];
      lazy[2 * idx + 2] += lazy[idx];
    }
    seg[idx] += lazy[idx];
    lazy[idx] = 0;
  }
}
void modify(int idx, int l, int r, int a, int b, int x) {
  upd(idx, l, r);
  if (l > b || r < a) return;
  if (l >= a && r <= b) {
    lazy[idx] += x;
    upd(idx, l, r);
  } else {
    int mid = (l + r) / 2;
    modify(2 * idx + 1, l, mid, a, b, x);
    modify(2 * idx + 2, mid + 1, r, a, b, x);
    seg[idx] = max(seg[2 * idx + 1], seg[2 * idx + 2]);
  }
}
int query(int idx, int l, int r, int a, int b) {
  upd(idx, l, r);
  if (l > b || r < a) return 0;
  if (l >= a && r <= b) return seg[idx];
  int mid = (l + r) / 2;
  return max(query(2 * idx + 1, l, mid, a, b),
             query(2 * idx + 2, mid + 1, r, a, b));
}
int main() {
  int n, kt;
  scanf("%d %d", &n, &kt);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) dp[0][i] = -1e9;
  for (int k = 1; k <= kt; k++) {
    build_tree(0, 0, n, dp[k - 1]);
    dp[k][0] = -1e9;
    vector<int> last(n + 1);
    for (int i = 1; i <= n; i++) {
      modify(0, 0, n, last[a[i]], i - 1, 1);
      dp[k][i] = query(0, 0, n, 0, i - 1);
      last[a[i]] = i;
    }
  }
  printf("%d\n", dp[kt][n]);
  return 0;
}
