#include <bits/stdc++.h>
using namespace std;
const int MAXN = 70000;
const int INF = 0x3f3f3f3f;
template <class T>
void Read(T &x) {
  x = 0;
  char c = getchar();
  bool flag = 0;
  while (c < '0' || '9' < c) {
    if (c == '-') flag = 1;
    c = getchar();
  }
  while ('0' <= c && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  if (flag) x = -x;
}
int a[MAXN + 10];
int last[MAXN + 10], now[MAXN + 10];
int n, m;
int val[MAXN * 3];
int lazy[MAXN * 3];
void updata(int x) { val[x] = max(val[x << 1], val[x << 1 | 1]); }
void pushdown(int x) {
  if (lazy[x]) {
    val[x << 1] += lazy[x], val[x << 1 | 1] += lazy[x];
    lazy[x << 1] += lazy[x], lazy[x << 1 | 1] += lazy[x];
    lazy[x] = 0;
  }
}
void build() {
  memset(val, 0, sizeof(val));
  memset(lazy, 0, sizeof(lazy));
}
void insert(int l, int r, int v, int ll, int rr, int x) {
  if (l <= ll && rr <= r)
    val[x] += v, lazy[x] += v;
  else {
    pushdown(x);
    int mid = (ll + rr) >> 1;
    if (l <= mid) insert(l, r, v, ll, mid, x << 1);
    if (mid < r) insert(l, r, v, mid + 1, rr, x << 1 | 1);
    updata(x);
  }
}
int query(int l, int r, int ll, int rr, int x) {
  if (l <= ll && rr <= r)
    return val[x];
  else {
    pushdown(x);
    int mid = (ll + rr) >> 1;
    int ret = 0;
    if (l <= mid) ret = max(ret, query(l, r, ll, mid, x << 1));
    if (mid < r) ret = max(ret, query(l, r, mid + 1, rr, x << 1 | 1));
    return ret;
  }
}
int dp[2][MAXN + 10];
int main() {
  memset(last, 0, sizeof(last));
  memset(now, 0, sizeof(now));
  Read(n), Read(m);
  for (int i = 1; i <= n; ++i) {
    Read(a[i]);
    last[i] = now[a[i]];
    now[a[i]] = i;
  }
  for (int j = 1; j <= n; ++j) dp[1][j] = dp[1][j - 1] + (last[j] == 0);
  for (int i = 2; i <= m; ++i) {
    build();
    for (int j = 1; j <= n; ++j) {
      if (max(i - 1, last[j]) <= j - 1)
        insert(max(i - 1, last[j]), j - 1, 1, 1, n, 1);
      if (j >= i) dp[i & 1][j] = query(i - 1, j - 1, 1, n, 1);
      insert(j, j, dp[(i & 1) ^ 1][j], 1, n, 1);
      dp[(i & 1) ^ 1][j] = 0;
    }
  }
  printf("%d\n", dp[m & 1][n]);
}
