#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const int N = 4e4 + 100;
int a[N], dp[N][55], fil[N];
int add, cnt[N], L = 1, R = 0;
struct persistent_segment_tree {
  int tree_deg, root[N];
  struct tree_node {
    int lc, rc;
    int val;
  } t[20001000];
  void modify(int& first, int k, int l, int r, int pos, int v) {
    t[first = ++tree_deg] = t[k];
    if (l == r) {
      t[first].val = v;
      return;
    }
    int mid = (l + r) >> 1;
    if (pos <= mid)
      modify(t[first].lc, t[k].lc, l, mid, pos, v);
    else
      modify(t[first].rc, t[k].rc, mid + 1, r, pos, v);
    t[first].val = t[t[first].lc].val + t[t[first].rc].val;
  }
  int query(int first, int l, int r, int ql, int qr) {
    if (l > qr || r < ql || l > r) return 0;
    if (ql <= l && r <= qr) return t[first].val;
    int mid = (l + r) >> 1;
    return query(t[first].lc, l, mid, ql, qr) +
           query(t[first].rc, mid + 1, r, ql, qr);
  }
} st;
int lst[N], nxt[N], hlp[N];
int n, k;
void cal(int l, int r, int optL, int optR, int cur) {
  if (l > r) return;
  int mid = (l + r) >> 1;
  int opt = -1, sta = min(optR, mid - 1);
  add = st.query(st.root[mid], 1, n, sta + 1, mid);
  for (int i = sta; i >= optL; i--) {
    if (dp[i][cur - 1] + add > dp[mid][cur]) {
      dp[mid][cur] = dp[i][cur - 1] + add;
      opt = i;
    }
    if (hlp[i] > mid) add++;
  }
  if (l == r) return;
  cal(l, mid - 1, optL, opt, cur);
  cal(mid + 1, r, opt, optR, cur);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  for (__typeof(n + 1) i = (1) - ((1) > (n + 1));
       i != (n + 1) - ((1) > (n + 1)); i += 1 - 2 * ((1) > (n + 1)))
    cin >> a[i], lst[i] = n + 1, nxt[i] = n + 1;
  for (__typeof(1) i = (n + 1) - ((n + 1) > (1)); i != (1) - ((n + 1) > (1));
       i += 1 - 2 * ((n + 1) > (1)))
    hlp[i] = nxt[a[i]], nxt[a[i]] = i;
  int tot = 0;
  for (__typeof(n + 1) i = (1) - ((1) > (n + 1));
       i != (n + 1) - ((1) > (n + 1)); i += 1 - 2 * ((1) > (n + 1))) {
    if (fil[a[i]] == 0) tot++;
    fil[a[i]]++;
    dp[i][1] = tot;
    st.modify(st.root[i], st.root[i - 1], 1, n, lst[a[i]], 0);
    st.modify(st.root[i], st.root[i], 1, n, i, 1);
    lst[a[i]] = i;
  }
  for (__typeof(k + 1) i = (2) - ((2) > (k + 1));
       i != (k + 1) - ((2) > (k + 1)); i += 1 - 2 * ((2) > (k + 1)))
    cal(1, n, 1, n, i);
  cout << dp[n][k] << endl;
}
