#include <bits/stdc++.h>
using namespace std;
const int MAX = 35005;
struct segtree {
  segtree *left, *right;
  int start, end, v, m;
  int lazy;
  segtree(int start, int end) : start(start), end(end), v(0), lazy(0) {
    if (start == end) {
      left = right = NULL;
    } else {
      m = (start + end) / 2;
      left = new segtree(start, m);
      right = new segtree(m + 1, end);
    }
  }
  void propagate() {
    if (lazy) {
      v += lazy;
      if (left != NULL) left->lazy += lazy;
      if (right != NULL) right->lazy += lazy;
      lazy = 0;
    }
  }
  void update(int a, int b, int val) {
    if (b < a) return;
    propagate();
    if (a == start && b == end) {
      lazy += val;
      propagate();
    } else {
      if (b <= m)
        left->update(a, b, val);
      else if (a > m)
        right->update(a, b, val);
      else
        left->update(a, m, val), right->update(m + 1, b, val);
      left->propagate();
      right->propagate();
      v = max(left->v, right->v);
    }
  }
  int query(int a, int b) {
    if (b < a) return 1;
    propagate();
    if (a == start && b == end) return v;
    if (b <= m) return left->query(a, b);
    if (a > m) return right->query(a, b);
    return max(left->query(a, m), right->query(m + 1, b));
  }
};
int dp[MAX][51];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> v(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
  }
  set<int> diff;
  for (int i = 1; i <= n; i++) {
    diff.insert(v[i]);
    dp[i][1] = diff.size();
  }
  for (int i = 2; i <= k; i++) {
    segtree cur(1, n);
    for (int j = 1; j <= n; j++) {
      cur.update(j, j, dp[j][i - 1]);
    }
    vector<int> last(n + 1, 1);
    for (int j = 1; j <= n; j++) {
      cur.update(last[v[j]], j - 1, 1);
      dp[j][i] = cur.query(1, j - 1);
      last[v[j]] = j;
    }
  }
  cout << dp[n][k] << '\n';
}
