#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[";
  for (auto vv : V) os << vv << ",";
  return os << "]";
}
template <class TH>
void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << '=' << h << '\n';
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}
const int N = 4e4 + 7;
const int K = 52;
int n;
int k;
int a[N];
int dp[N][K];
int prv[N];
int li[N];
struct SegTreeLazy {
  int t[4 * (1 << 16) + 7];
  int lazy[4 * (1 << 16) + 7];
  void init() {
    memset(t, 0, sizeof t);
    memset(lazy, 0, sizeof lazy);
  }
  void push(int v, int tl, int tr) {
    t[v] += lazy[v];
    if (tl != tr) {
      lazy[2 * v] += lazy[v];
      lazy[2 * v + 1] += lazy[v];
    }
    lazy[v] = 0;
  }
  void add(int v, int tl, int tr, int l, int r, int val) {
    push(v, tl, tr);
    if (tl > r || tr < l) return;
    if (l <= tl && tr <= r) {
      lazy[v] += val;
      push(v, tl, tr);
      return;
    }
    int mid = (tl + tr) / 2;
    add(2 * v, tl, mid, l, r, val);
    add(2 * v + 1, mid + 1, tr, l, r, val);
    t[v] = max(t[2 * v], t[2 * v + 1]);
  }
  void add(int l, int r, int val) { add(1, 0, n, l, r, val); }
  int query(int v, int tl, int tr, int l, int r) {
    push(v, tl, tr);
    if (tl > r || tr < l) return -10000000;
    if (l <= tl && tr <= r) return t[v];
    int mid = (tl + tr) / 2;
    return max(query(2 * v, tl, mid, l, r),
               query(2 * v + 1, mid + 1, tr, l, r));
  }
  int query(int l, int r) { return query(1, 0, n, l, r); }
} seg;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) {
    prv[i] = li[a[i]];
    li[a[i]] = i;
  }
  for (int i = 0; i <= k - 1; ++i) {
    seg.init();
    for (int j = 1; j <= n; ++j) seg.add(j, j, dp[i][j]);
    for (int j = 1; j <= n; ++j) {
      int x = prv[j];
      seg.add(x, j - 1, 1);
      dp[i + 1][j] = seg.query(0, j - 1);
    }
  }
  cout << dp[k][n] << '\n';
  return 0;
}
