#include <bits/stdc++.h>
#pragma GCC optimize("O3", "Ofast", "fast-math", "unroll-loops")
using namespace std;
const int maxn = 36000;
const int maxc = 51;
const int inf = 1e8;
int p[maxn];
int dp[maxn][maxc];
struct segtree {
  segtree *l = 0, *r = 0;
  int ld, rd, ma = 0, add = 0;
  segtree(int cur_l = 0, int cur_r = 0, int ind = 0) {
    ld = cur_l;
    rd = cur_r;
    if (cur_l < cur_r - 1) {
      int m = (cur_l + cur_r) / 2;
      l = new segtree(cur_l, m, ind);
      r = new segtree(m, cur_r, ind);
      ma = max(l->ma, r->ma);
    } else {
      ma = dp[cur_l][ind];
    }
  }
  void print() {
    cout << ld << " " << rd << " " << ma << " " << add << '\n';
    if (l) {
      l->print();
      r->print();
    }
  }
  void push() {
    ma += add;
    if (l) {
      l->add += add;
      r->add += add;
    }
    add = 0;
  }
  int get_max(int L, int R) {
    push();
    if (L <= ld && rd <= R) {
      return ma;
    }
    if (max(ld, L) >= min(rd, R)) {
      return 0;
    }
    return max(l->get_max(L, R), r->get_max(L, R));
  }
  void update(int L, int R, int x) {
    push();
    if (L <= ld && rd <= R) {
      add += x;
      push();
    } else if (l && max(ld, L) < min(rd, R)) {
      l->update(L, R, x);
      r->update(L, R, x);
      ma = max(l->ma, r->ma);
    }
  }
};
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int i, j, n, k;
  cin >> n >> k;
  set<int> s;
  map<int, int> last;
  for (j = 1; j <= k; j++) {
    for (i = 0; i < j; i++) {
      dp[i][j] = -inf;
    }
  }
  for (i = 1; i <= n; i++) {
    int x;
    cin >> x;
    s.insert(x);
    dp[i][1] = s.size();
    if (last.find(x) != last.end()) {
      p[i] = last[x];
    } else {
      p[i] = 0;
    }
    last[x] = i;
  }
  segtree g = segtree(0, n + 1, 1);
  for (j = 2; j <= k; j++) {
    for (i = j; i <= n; i++) {
      g.update(p[i], i, 1);
      dp[i][j] = g.get_max(1, i);
    }
    g = segtree(0, n + 1, j);
  }
  cout << dp[n][k] << '\n';
  return 0;
}
