#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> a;
bool read() {
  if (scanf("%d%d", &n, &k) < 2) {
    return 0;
  }
  a.resize(n);
  for (int i = 0; i < int(n); ++i) {
    scanf("%d", &a[i]);
    --a[i];
  }
  return 1;
}
const int INF = 1e9;
struct SegmTree {
  vector<int> add;
  vector<int> mx;
  int sz;
  SegmTree(int n = 0) {
    sz = 1;
    while (sz < n) sz *= 2;
    add.assign(sz * 2, 0);
    mx.assign(sz * 2, 0);
  }
  void push(int v) {
    add[v * 2] += add[v];
    add[v * 2 + 1] += add[v];
    mx[v * 2] += add[v];
    mx[v * 2 + 1] += add[v];
    add[v] = 0;
  }
  void recalc(int v) {
    assert(!add[v]);
    mx[v] = max(mx[v * 2], mx[v * 2 + 1]);
  }
  void go_add(int v, int tl, int tr, int l, int r, int val) {
    l = max(l, tl);
    r = min(r, tr);
    if (l > r) {
      return;
    }
    if (l == tl && r == tr) {
      add[v] += val;
      mx[v] += val;
      return;
    }
    push(v);
    int tm = (tl + tr) >> 1;
    go_add(v * 2, tl, tm, l, r, val);
    go_add(v * 2 + 1, tm + 1, tr, l, r, val);
    recalc(v);
  }
  void go_add(int l, int r, int val) { go_add(1, 0, sz - 1, l, r, val); }
  int get_max(int v, int tl, int tr, int l, int r) {
    l = max(l, tl);
    r = min(r, tr);
    if (l > r) {
      return -INF;
    }
    if (l == tl && r == tr) {
      return mx[v];
    }
    push(v);
    int tm = (tl + tr) >> 1;
    int res =
        max(get_max(v * 2, tl, tm, l, r), get_max(v * 2 + 1, tm + 1, tr, l, r));
    recalc(v);
    return res;
  }
  int get_max(int l, int r) { return get_max(1, 0, sz - 1, l, r); }
};
vector<int> recalc(const vector<int>& dp) {
  vector<int> ans(n + 1, -INF);
  ans[0] = 0;
  SegmTree T(n + 1);
  T.go_add(0, 0, dp[0]);
  vector<int> last(n, -1);
  for (int i = 0; i < int(n); ++i) {
    int prev_________________ = last[a[i]];
    T.go_add(prev_________________ + 1, i, +1);
    ans[i + 1] = T.get_max(0, i);
    T.go_add(i + 1, i + 1, dp[i + 1]);
    last[a[i]] = i;
  }
  return ans;
}
int solve() {
  vector<int> dp(n + 1, -INF);
  dp[0] = 0;
  for (int it = 0; it < int(k); ++it) {
    dp = recalc(dp);
  }
  return dp[n];
}
int main() {
  while (read()) {
    printf("%d\n", solve());
  }
  return 0;
}
