#include <bits/stdc++.h>
using namespace std;
const int N = 400000;
int n, m, a[N], last[N], a1[N], dp[N][55];
std::set<int> s;
struct Node {
  int l, r, flag, maxn;
} node[N << 2];
inline void pushup(int p) {
  node[p].maxn = max(node[p << 1].maxn, node[p << 1 | 1].maxn);
}
void build(int k, int p, int l, int r) {
  node[p].l = l;
  node[p].r = r;
  node[p].flag = 0;
  if (l == r) {
    node[p].maxn = dp[l][k];
    return;
  }
  int mid = l + r >> 1;
  build(k, p << 1, l, mid);
  build(k, p << 1 | 1, mid + 1, r);
  pushup(p);
}
inline void pushdown(int p) {
  if (node[p].flag != 0) {
    node[p << 1].flag += node[p].flag;
    node[p << 1 | 1].flag += node[p].flag;
    node[p << 1].maxn += node[p].flag;
    node[p << 1 | 1].maxn += node[p].flag;
    node[p].flag = 0;
  }
}
void solve(int p, int l, int r, int u, int v) {
  if (u <= l && r <= v) {
    node[p].flag++;
    node[p].maxn++;
    return;
  }
  pushdown(p);
  int mid = (l + r) >> 1;
  if (u <= mid) solve(p << 1, l, mid, u, v);
  if (mid + 1 <= v) solve(p << 1 | 1, mid + 1, r, u, v);
  pushup(p);
}
int getmax(int p, int l, int r, int u, int v) {
  if (u <= l && r <= v) return node[p].maxn;
  pushdown(p);
  int mid = (l + r) >> 1, ans = 0;
  if (u <= mid) ans = max(ans, getmax(p << 1, l, mid, u, v));
  if (mid + 1 <= v) ans = max(ans, getmax(p << 1 | 1, mid + 1, r, u, v));
  return ans;
}
void Dp(int k) {
  build(k - 1, 1, 1, n);
  for (int i = k; i <= n; i++) {
    solve(1, 1, n, last[i], i - 1);
    dp[i][k] = max(dp[i][k - 1], getmax(1, 1, n, k - 1, i - 1));
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    last[i] = a1[a[i]];
    a1[a[i]] = i;
    s.insert(a[i]);
    dp[i][1] = s.size();
  }
  for (int i = 2; i <= m; i++) Dp(i);
  printf("%d", dp[n][m]);
  return 0;
}
