#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int mod = 1e9 + 7;
const int N3 = 1e3 + 10;
const int INF = 2e9 + 10;
const long long LINF = 2e18;
int n, k, a[N], prv[N], last[N];
struct SegTree {
  int mx[N * 2], add[N * 2];
  void push(int x, int tl, int tr) {
    if (tl < tr) {
      add[x << 1] += add[x];
      add[x << 1 | 1] += add[x];
    }
    mx[x] += add[x];
    add[x] = 0;
  }
  void upd(int x, int tl, int tr, int l, int r, int val) {
    if (tr < tl) return;
    push(x, tl, tr);
    if (tr < l || r < tl) return;
    if (l <= tl && tr <= r) {
      add[x] += val;
      push(x, tl, tr);
      return;
    }
    int md = (tl + tr) / 2;
    upd(x << 1, tl, md, l, r, val);
    upd(x << 1 | 1, md + 1, tr, l, r, val);
    mx[x] = max(mx[x << 1], mx[x << 1 | 1]);
  }
  int get(int x, int tl, int tr, int l, int r) {
    if (tr < tl) return 0;
    push(x, tl, tr);
    if (tr < l || r < tl) return 0;
    if (l <= tl && tr <= r) {
      return mx[x];
    }
    int md = (tl + tr) / 2;
    return max(get(x << 1, tl, md, l, r), get(x << 1 | 1, md + 1, tr, l, r));
  }
} t[52];
int main() {
  if ("" != "") {
    freopen(
        ""
        ".in",
        "r", stdin);
    freopen(
        ""
        ".out",
        "w", stdout);
  }
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    prv[i] = last[a[i]];
    last[a[i]] = i;
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= min(i, k); ++j) t[j].upd(1, 0, n, prv[i], i - 1, 1);
    for (int j = 0; j <= min(i, k) - 1; ++j) {
      int res = t[j].get(1, 0, n, j, i - 1);
      t[j + 1].upd(1, 0, n, i, i, res);
    }
  }
  cout << t[k].get(1, 0, n, n, n);
  return 0;
}
