#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
const long long INF = 1e18 + 1LL;
const double pi = acos(-1.0);
const int N = 5e5 + 10, M = 1e3 + 20, inf = 2e9;
int dp[60][N], k;
int lazy[N];
int mx[N], v[N], n;
void push_up(int i) { mx[i] = max(mx[i << 1], mx[i << 1 | 1]); }
void push_down(int i, int ll, int rr) {
  if (ll == rr) return;
  if (lazy[i]) {
    lazy[i << 1] += lazy[i];
    lazy[i << 1 | 1] += lazy[i];
    mx[i << 1] += lazy[i];
    mx[i << 1 | 1] += lazy[i];
    lazy[i] = 0;
  }
}
void build(int i, int ll, int rr, int p) {
  lazy[i] = 0;
  mx[i] = 0;
  v[i] = 0;
  if (ll == rr) {
    v[i] = dp[p][ll - 1];
    mx[i] = v[i];
    return;
  }
  build(i << 1, ll, ((ll + rr) >> 1), p);
  build(i << 1 | 1, ((ll + rr) >> 1) + 1, rr, p);
  push_up(i);
}
void update(int i, int ll, int rr, int x, int y, int c) {
  push_down(i, ll, rr);
  if (ll == x && rr == y) {
    mx[i] += c;
    lazy[i] += c;
    return;
  }
  if (y <= ((ll + rr) >> 1))
    update(i << 1, ll, ((ll + rr) >> 1), x, y, c);
  else if (x > ((ll + rr) >> 1))
    update(i << 1 | 1, ((ll + rr) >> 1) + 1, rr, x, y, c);
  else
    update(i << 1, ll, ((ll + rr) >> 1), x, ((ll + rr) >> 1), c),
        update(i << 1 | 1, ((ll + rr) >> 1) + 1, rr, ((ll + rr) >> 1) + 1, y,
               c);
  push_up(i);
}
int ask(int i, int ll, int rr, int x, int y) {
  push_down(i, ll, rr);
  if (ll == x && rr == y) {
    return mx[i];
  }
  if (y <= ((ll + rr) >> 1))
    return ask(i << 1, ll, ((ll + rr) >> 1), x, y);
  else if (x > ((ll + rr) >> 1))
    return ask(i << 1 | 1, ((ll + rr) >> 1) + 1, rr, x, y);
  else
    return max(
        ask(i << 1, ll, ((ll + rr) >> 1), x, ((ll + rr) >> 1)),
        ask(i << 1 | 1, ((ll + rr) >> 1) + 1, rr, ((ll + rr) >> 1) + 1, y));
  push_up(i);
}
int mp[N], last[N], a[N];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    last[i] = mp[a[i]];
    mp[a[i]] = i;
  }
  for (int i = 1; i <= k; ++i) {
    build(1, 1, n, i - 1);
    for (int j = 1; j <= n; ++j) {
      update(1, 1, n, last[j] + 1, j, 1);
      dp[i][j] = ask(1, 1, n, 1, j);
    }
  }
  cout << dp[k][n] << endl;
  return 0;
}
