#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[350010], dp[350010][55], pre[350010], f[350010], pos[350010];
struct Node {
  int x, l, r, sum, tag;
} t[350010 << 2];
inline int ls(int x) { return x << 1; }
inline int rs(int x) { return x << 1 | 1; }
inline void push_up(int x) { t[x].sum = max(t[ls(x)].sum, t[rs(x)].sum); }
inline void solve(int x, int k) {
  t[x].sum += k;
  t[x].tag += k;
}
inline void build(int x, int l, int r) {
  t[x].l = l, t[x].r = r;
  t[x].tag = 0;
  if (l == r) {
    t[x].sum = f[l];
    return;
  }
  int mid = (l + r) >> 1;
  build(ls(x), l, mid);
  build(rs(x), mid + 1, r);
  push_up(x);
}
inline void push_down(int x) {
  if (t[x].tag) {
    solve(ls(x), t[x].tag);
    solve(rs(x), t[x].tag);
    t[x].tag = 0;
  }
}
inline void update(int x, int ll, int rr) {
  int l = t[x].l, r = t[x].r;
  if (ll <= l && r <= rr) {
    solve(x, 1);
    return;
  }
  int mid = (l + r) >> 1;
  push_down(x);
  if (ll <= mid) update(ls(x), ll, rr);
  if (mid < rr) update(rs(x), ll, rr);
  push_up(x);
}
inline int query(int x, int ll, int rr) {
  int l = t[x].l, r = t[x].r;
  if (ll <= l && r <= rr) return t[x].sum;
  int mid = (l + r) >> 1, cur_ans = 0;
  push_down(x);
  if (ll <= mid) cur_ans = max(cur_ans, query(ls(x), ll, rr));
  if (mid < rr) cur_ans = max(cur_ans, query(rs(x), ll, rr));
  return cur_ans;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    pre[i] = pos[a[i]];
    pos[a[i]] = i;
  }
  for (int j = 1; j <= k; j++) {
    build(1, 0, n - 1);
    for (int i = 1; i <= n; i++)
      update(1, pre[i], i - 1), f[i] = query(1, 0, i - 1);
  }
  printf("%d\n", f[n]);
  return 0;
}
