#include <bits/stdc++.h>
using namespace std;
const int N = 35005;
int seg[4 * N];
int lazy[4 * N];
int a[N];
int dp[N];
int n;
int Merge(int a, int b) { return max(a, b); }
void push(int id, int l, int r) {
  seg[id] += lazy[id];
  if (l != r) {
    lazy[id * 2] += lazy[id];
    lazy[id * 2 + 1] += lazy[id];
  }
  lazy[id] = 0;
}
void update(int su, int eu, int val, int id = 1, int l = 0, int r = n - 1) {
  push(id, l, r);
  if (l >= su && r <= eu) {
    lazy[id] += val;
    push(id, l, r);
    return;
  }
  if (r < su || l > eu) return;
  int mid = (l + r) / 2;
  update(su, eu, val, id * 2, l, mid);
  update(su, eu, val, id * 2 + 1, mid + 1, r);
  seg[id] = Merge(seg[id * 2], seg[id * 2 + 1]);
}
int query(int s, int e, int id = 1, int l = 0, int r = n - 1) {
  push(id, l, r);
  if (l >= s && r <= e) return seg[id];
  if (r < s || l > e) return 0;
  int mid = (l + r) / 2;
  return Merge(query(s, e, id * 2, l, mid),
               query(s, e, id * 2 + 1, mid + 1, r));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int k, ans = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int j = 0; j < k; j++) {
    vector<int> lst(n, -1);
    for (int i = 0; i < n; i++) {
      update(lst[a[i] - 1] + 1, i, 1);
      ans = max(ans, dp[i + 1] = query(j, i));
      lst[a[i] - 1] = i;
    }
    memset(seg, 0, sizeof seg);
    memset(lazy, 0, sizeof lazy);
    for (int i = 0; i < n; i++) update(i, i, dp[i]);
  }
  cout << ans << '\n';
  return 0;
}
