#include <bits/stdc++.h>
using namespace std;
int tree[3 * 200005], lazy[3 * 200005];
int arr[200005], last[200005];
int dp[200005][55];
void propagate(int n, int l, int r) {
  tree[n] += lazy[n];
  if (l != r) {
    lazy[2 * n] += lazy[n];
    lazy[2 * n + 1] += lazy[n];
  }
  lazy[n] = 0;
}
void combine(int n) { tree[n] = max(tree[2 * n], tree[2 * n + 1]); }
void init(int n, int l, int r) {
  tree[n] = 0;
  lazy[n] = 0;
  if (l == r) return;
  int mid = (l + r) / 2;
  init(2 * n, l, mid);
  init(2 * n + 1, mid + 1, r);
}
void update(int n, int l, int r, int i, int j, int val = 1) {
  propagate(n, l, r);
  if (l > j || r < i) return;
  if (l >= i && r <= j) {
    lazy[n] += val;
    propagate(n, l, r);
    return;
  }
  int mid = (l + r) / 2;
  update(2 * n, l, mid, i, j, val);
  update(2 * n + 1, mid + 1, r, i, j, val);
  combine(n);
}
int query(int n, int l, int r, int i, int j) {
  propagate(n, l, r);
  if (l > j || r < i) return 0;
  if (l >= i && r <= j) return tree[n];
  int mid = (l + r) / 2;
  return max(query(2 * n, l, mid, i, j), query(2 * n + 1, mid + 1, r, i, j));
}
void solve() {
  int i, j, k, l, m, n, x, y;
  cin >> n >> k;
  for (i = 1; i <= n; i++) cin >> arr[i];
  for (j = 1; j <= k; j++) {
    for (i = 1; i <= n; i++) last[i] = 0;
    dp[0][0] = 1;
    for (i = 1; i <= n; i++) {
      update(1, 0, n, last[arr[i]], i - 1, 1);
      dp[i][j] = query(1, 0, n, 0, i - 1);
      update(1, 0, n, i, i, dp[i][j - 1]);
      last[arr[i]] = i;
    }
    init(1, 0, n);
  }
  cout << dp[n][k] << endl;
}
int32_t main() {
  int t;
  t = 1;
  ios::sync_with_stdio(false);
  cin.tie(0);
  while (t--) solve();
  return 0;
}
