#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const int mod = 1000000007;
inline void gn(long long &x) {
  int sg = 1;
  char c;
  while (((c = getchar()) < '0' || c > '9') && c != '-')
    ;
  c == '-' ? (sg = -1, x = 0) : (x = c - '0');
  while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - '0';
  x *= sg;
}
inline void gn(int &x) {
  long long t;
  gn(t);
  x = t;
}
inline void gn(unsigned long long &x) {
  long long t;
  gn(t);
  x = t;
}
long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; }
long long powmod(long long a, long long x, long long mod) {
  long long t = 1ll;
  while (x) {
    if (x & 1) t = t * a % mod;
    a = a * a % mod;
    x >>= 1;
  }
  return t;
}
const int maxn = 35555;
const int N = 35000 + 5, MX = 35000 + 5;
inline int read() {
  char c = getchar();
  int x = 0, f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
int n, Q, x, ql, qr, last[N], pos[MX];
struct node {
  int l, r, size;
} t[N * 40];
int sz, root[N];
void ins(int &x, int l, int r, int p) {
  t[++sz] = t[x];
  x = sz;
  t[x].size++;
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (p <= mid)
    ins(t[x].l, l, mid, p);
  else
    ins(t[x].r, mid + 1, r, p);
}
int que(int x, int y, int l, int r, int ql, int qr) {
  if (ql <= l && r <= qr)
    return t[y].size - t[x].size;
  else {
    int mid = (l + r) >> 1, ans = 0;
    if (ql <= mid) ans += que(t[x].l, t[y].l, l, mid, ql, qr);
    if (mid < qr) ans += que(t[x].r, t[y].r, mid + 1, r, ql, qr);
    return ans;
  }
}
map<int, int> vis[35555];
int ask(int ql, int qr) {
  if (vis[ql].count(qr)) return vis[ql][qr];
  int ret = que(root[ql - 1], root[qr], 0, n, 0, ql - 1);
  vis[ql][qr] = ret;
  return ret;
}
int dp[35005][55];
int has[35005];
int v[35005];
int base;
void solve(int l, int r, int dl, int dr) {
  if (l > r) return;
  int m = (l + r) >> 1, i, dm;
  for (i = dl; i <= dr; i++) {
    int nowv = dp[i - 1][base - 1] + ask(i, m);
    if (nowv > dp[m][base]) {
      dp[m][base] = nowv;
      dm = i;
    }
  }
  solve(l, m - 1, dl, dm);
  solve(m + 1, r, dm, dr);
}
int main() {
  int k;
  memset((has), 0, sizeof(has));
  n = read();
  k = read();
  for (int i = 1; i <= n; i++) {
    x = read();
    v[i] = x;
    last[i] = pos[x];
    pos[x] = i;
  }
  for (int i = 1; i <= n; i++)
    root[i] = root[i - 1], ins(root[i], 0, n, last[i]);
  int tot = 0;
  for (int i = (1); i <= (n); i++) {
    if (has[v[i]] == 0) tot++;
    has[v[i]]++;
    dp[i][1] = tot;
  }
  for (int i = (2); i <= (k); i++) {
    base = i;
    solve(1, n, 1, n);
  }
  printf("%d\n", dp[n][k]);
}
