#include <bits/stdc++.h>
using namespace std;
template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}
const int MAX = 1 << 20;
int tree[2 * MAX + 7], lazy[2 * MAX + 7];
inline void propagate(int node, int l, int r) {
  if (lazy[node]) {
    tree[node] += lazy[node];
    if (l != r) {
      lazy[2 * node] += lazy[node];
      lazy[2 * node + 1] += lazy[node];
    }
    lazy[node] = 0;
  }
}
void update(int a, int b, int v, int node = 1, int l = 0, int r = MAX - 1) {
  if (a > b) return;
  propagate(node, l, r);
  if (r < a || b < l) return;
  if (a <= l && r <= b) {
    lazy[node] += v;
    propagate(node, l, r);
    return;
  }
  int m = (l + r) / 2;
  update(a, b, v, 2 * node, l, m);
  update(a, b, v, 2 * node + 1, m + 1, r);
  tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}
const int N = 35e3 + 7;
int n, k, t[N], dp[51][N], pre[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> t[i];
  for (int i = 1; i <= k; i++) {
    fill(tree, tree + 2 * MAX, 0);
    fill(lazy, lazy + 2 * MAX, 0);
    fill(pre, pre + n + 1, 0);
    for (int j = 1; j <= n; j++) {
      update(0, j - 1, 1);
      if (pre[t[j]] != 0) update(0, pre[t[j]] - 1, -1);
      pre[t[j]] = j;
      if (i <= j) {
        update(j - 1, j - 1, dp[i - 1][j - 1]);
        dp[i][j] = tree[1];
      }
    }
  }
  cout << dp[k][n] << "\n";
  return 0;
}
