#include <bits/stdc++.h>
using namespace std;
template <class T>
void dbg(const char* xn, T x) {
  if (0) cout << xn << ": " << x << "\n";
}
template <class T, class... TA>
void dbg(const char* xn, T x, TA... t) {
  while (*xn != ',')
    if (0) cout << *xn++;
  if (0) cout << ": " << x << ",";
  dbg(xn + 1, t...);
}
template <class T>
inline bool upd_max(T& x, T y) {
  return y > x ? x = y, true : false;
}
template <class T>
inline bool upd_min(T& x, T y) {
  return y < x ? x = y, true : false;
}
const int N = 50007;
const int M = (1 << 16);
long long n, boxes, arr[N], prvSame[N], last[N], dp[57][N];
long long load[2 * M], sub[2 * M];
void Insert(long long a, long long b, long long val, long long v = 1,
            long long l = 0, long long r = M - 1) {
  if (a > b || l > b || a > r) return;
  if (a <= l && r <= b) {
    load[v] += val;
    sub[v] += val;
    return;
  }
  Insert(a, b, val, 2 * v, l, (l + r) / 2);
  Insert(a, b, val, 2 * v + 1, (l + r) / 2 + 1, r);
  sub[v] = load[v] + max(sub[2 * v], sub[2 * v + 1]);
}
long long Query(long long a, long long b, long long v = 1, long long l = 0,
                long long r = M - 1) {
  if (a > b || l > b || a > r) return -1000000007LL;
  if (a <= l && r <= b) return sub[v];
  return load[v] + max(Query(a, b, 2 * v, l, (l + r) / 2),
                       Query(a, b, 2 * v + 1, (l + r) / 2 + 1, r));
}
void BuildTree(long long k) {
  for (long long i = 0; i < 2 * M; ++i) {
    load[i] = 0;
    sub[i] = -1000000007LL;
  }
  for (long long i = 0; i <= n; ++i) {
    sub[M + i] = dp[k][i];
  }
  for (long long i = M - 1; i >= 1; --i) {
    sub[i] = max(sub[2 * i], sub[2 * i + 1]);
  }
}
void solveDP() {
  for (long long k = 0; k < (boxes + 1); ++k)
    for (long long i = 0; i < (n + 1); ++i) dp[k][i] = -1000000007LL;
  dp[0][0] = 0;
  for (long long k = 1; k <= boxes; ++k) {
    BuildTree(k - 1);
    for (long long i = 1; i <= n; ++i) {
      Insert(prvSame[i], i - 1, 1);
      dp[k][i] = Query(0, i - 1);
    }
  }
  cout << dp[boxes][n];
}
void solve() {
  cin >> n >> boxes;
  for (long long i = 1; i <= (n); ++i) {
    cin >> arr[i];
    prvSame[i] = last[arr[i]];
    last[arr[i]] = i;
  }
  solveDP();
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout << fixed << setprecision(10);
  solve();
  return 0;
}
