#include <bits/stdc++.h>
using namespace std;
int n, k;
int c[50003];
int a[50003], pre[50003];
int dp[50003][52];
struct SegTree {
  struct SegNode {
    int l, r;
    int add;
    int max;
  } tree[50003 << 2];
  void clear() { memset(tree, 0, sizeof tree); }
  void build(int p, int l, int r, int j) {
    tree[p].add = 0;
    tree[p].l = l, tree[p].r = r;
    if (l == r) {
      tree[p].max = dp[l - 1][j];
      return;
    }
    int mid = (l + r) / 2;
    build(p * 2, l, mid, j);
    build(p * 2 + 1, mid + 1, r, j);
    tree[p].max = max(tree[p * 2].max, tree[p * 2 + 1].max);
  }
  void spread(int p) {
    if (tree[p].add) {
      tree[p * 2].max += tree[p].add;
      tree[p * 2 + 1].max += tree[p].add;
      tree[p * 2].add += tree[p].add;
      tree[p * 2 + 1].add += tree[p].add;
      tree[p].add = 0;
    }
  }
  void change(int p, int l, int r, long long d) {
    if (l <= tree[p].l && r >= tree[p].r) {
      tree[p].max += d;
      tree[p].add += d;
      return;
    }
    spread(p);
    int mid = (tree[p].l + tree[p].r) / 2;
    if (l <= mid) change(p * 2, l, r, d);
    if (r > mid) change(p * 2 + 1, l, r, d);
    tree[p].max = max(tree[p * 2].max, tree[p * 2 + 1].max);
  }
  int ask4max(int p, int l, int r) {
    if (l <= tree[p].l && r >= tree[p].r) return tree[p].max;
    spread(p);
    int mid = (tree[p].l + tree[p].r) / 2;
    int val = 0;
    if (l <= mid) val = max(val, ask4max(p * 2, l, r));
    if (r > mid) val = max(val, ask4max(p * 2 + 1, l, r));
    return val;
  }
} T[53];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = (1); i < n + 1; i++) scanf("%d", &a[i]);
  for (int i = (1); i < n + 1; i++) {
    if (!c[a[i]])
      pre[i] = 0, c[a[i]] = i;
    else
      pre[i] = c[a[i]], c[a[i]] = i;
  }
  for (int j = (1); j < k + 1; j++) {
    T[j - 1].clear();
    T[j - 1].build(1, 1, n, j - 1);
    for (int i = (1); i < n + 1; i++) {
      T[j - 1].change(1, pre[i] + 1, i, 1);
      if (i < j) continue;
      dp[i][j] = T[j - 1].ask4max(1, 1, i);
    }
  }
  int maxx = 0;
  for (int j = (1); j < k + 1; j++) maxx = max(maxx, dp[n][j]);
  printf("%d", maxx);
  return 0;
}
