#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int nax = 35020;
struct node {
  int sum, l, r;
};
node t[int(2e6)];
struct stree {
  vector<int> a, rts;
  int n, idx;
  inline int oper(int a, int b) { return a + b; }
  stree() {}
  int build(int tl, int tr) {
    int v = idx++;
    if (tl == tr) {
      t[v].sum = a[tl];
      return v;
    }
    int tm = (tl + tr) >> 1;
    t[v].l = build(tl, tm);
    t[v].r = build(tm + 1, tr);
    t[v].sum = t[t[v].l].sum + t[t[v].r].sum;
    return v;
  }
  stree(vector<int> &arr) {
    n = ((int)arr.size());
    a = arr;
    idx = 0;
    rts.push_back(0);
    build(0, n - 1);
  }
  int query(int v, int tl, int tr, int l, int r) {
    if (l > r) return 0;
    if (l == tl && tr == r) {
      return t[v].sum;
    }
    int tm = (tl + tr) >> 1;
    return oper(query(t[v].l, tl, tm, l, min(r, tm)),
                query(t[v].r, tm + 1, tr, max(l, tm + 1), r));
  }
  int upd(int prev, int tl, int tr, int pos, int val) {
    int v = idx++;
    t[v] = t[prev];
    if (tl == tr) {
      t[v].sum = val;
      return v;
    }
    int tm = (tl + tr) / 2;
    if (pos <= tm) {
      t[v].l = upd(t[v].l, tl, tm, pos, val);
    } else {
      t[v].r = upd(t[v].r, tm + 1, tr, pos, val);
    }
    t[v].sum = t[t[v].l].sum + t[t[v].r].sum;
    return v;
  }
  int query(int id, int l, int r) { return query(rts[id], 0, n - 1, l, r); }
  void upd(int pos, int val) {
    int id = upd(rts.back(), 0, n - 1, pos, val);
    rts.push_back(id);
  }
};
int n, K;
int a[nax], pos[nax], nums[nax];
int dp[55][nax];
stree st;
int cost(int l, int r) {
  --l, --r;
  return st.query(pos[r], l, r);
}
void compute(int k, int l, int r, int optl, int optr) {
  if (l > r) return;
  int m = (l + r) / 2;
  pair<int, int> best = {-inf, min(optr, m)};
  for (int j = optl; j <= min(optr, m); ++j) {
    int tmp = dp[k - 1][j - 1] + cost(j, m);
    if (best.first <= tmp) {
      best.first = tmp;
      best.second = j;
    }
  }
  int op = best.second;
  dp[k][m] = best.first;
  compute(k, l, m - 1, optl, op);
  compute(k, m + 1, r, op, optr);
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << setprecision(20) << fixed;
  cin >> n >> K;
  memset(nums, -1, sizeof nums);
  vector<int> tmp(n);
  st = stree(tmp);
  tmp.clear();
  for (int i = 0; i < (int)n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < (int)n; ++i) {
    int &p = nums[a[i]];
    if (p != -1) {
      st.upd(p, 0);
    }
    p = i;
    st.upd(p, 1);
    pos[p] = ((int)st.rts.size()) - 1;
  }
  for (int i = 0; i <= n; ++i) dp[0][i] = -inf;
  dp[0][0] = 0;
  for (int k = 1; k <= K; ++k) {
    compute(k, 1, n, 1, n);
  }
  cout << dp[K][n] << '\n';
  return 0;
}
